Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Dec 2012
    Location
    USA
    Posts
    82
    Thanks
    3
    Thanked 17 Times in 17 Posts

    Mail() is not rendering HTML

    I have a page that, after processing massive amounts of user-input, emails a confirmation email to both the user and the system admin.

    The email to the system admin renders fine in all the clients I have browsed it in. However the email to the user does not render at all, it is just plain text.

    The odd thing is that they both use the exact same headers array...

    PHP Code:
    $headers = array();
                    
    $headers[0] = 'MIME-Version: 1.0';
                    
    $headers[1] = 'Content-type: text/html; charset=utf-8';
                    
    $headers[2] = 'Content-Transfer-Encoding: 8bit';
                    
    $headers[3] = "From: no-reply@****.com";
                    
    $headers[4] = "Bcc: archive@****.com";
                    
    $headers[5] = "Reply-To: no-reply@****.com";
                    
    $headers[6] = "X-Mailer: PHP/".phpversion(); 
    Here is the portion of the code that sends the emails. The only difference is that the email to the user has a "Thank You" amended to the end of the subject line.

    PHP Code:
                if(!mail($to$subject$messageimplode("\r\n"$headers))){
                    
    // Does error catching stuff - irrelevant
                
    }else{
                    
    mail($email$subject.' Thank You!'$messageimplode("\r\n"$headers));
                } 
    This is extremely baffling... I have declared the doctype as HTML in both the email body and in the email header... The first email sent renders fine, the second renders as plain text.


    EDIT::

    I found the cause behind this. Poorly written email clients...
    Last edited by TFlan; 01-08-2013 at 07:23 PM.

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,090
    Thanks
    51
    Thanked 506 Times in 493 Posts
    It's weird. You're only sending the second email IF the first one failed? - If the first call to mail() failed the second one won't succeed anyway.

    I'm really not sure how you could even be seeing both emails anyway with that logic.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #3
    New Coder
    Join Date
    Dec 2012
    Location
    USA
    Posts
    82
    Thanks
    3
    Thanked 17 Times in 17 Posts
    You have the if statement backwards - if the mail fails, do this. if not mail again.

    There is a '!'

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,090
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Same principle though isn't it. The point is, you're claiming to be having trouble with both yet in reality only one should be getting sent anyway
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #5
    New Coder
    Join Date
    Dec 2012
    Location
    USA
    Posts
    82
    Thanks
    3
    Thanked 17 Times in 17 Posts
    No,

    X = Mail sent status

    PHP Code:
    if(!$x){ // if $x == false
        // Error
    }else{
        
    mail(...);

    ==

    Also, if you read the OP, you would know that BOTH ARE being sent, however only one is (was) being rendered as HTML

  • #6
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,090
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Ok nevermind. For future reference, it's usually better not to negate the if (). Do the true first and the false after. You're doing the false / error first and the true after. Slightly strange and a bit confusing.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •