Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-07-2013, 08:38 PM   PM User | #1
TFlan
New Coder

 
Join Date: Dec 2012
Location: USA
Posts: 82
Thanks: 3
Thanked 17 Times in 17 Posts
TFlan is an unknown quantity at this point
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..
TFlan is offline   Reply With Quote
Old 01-07-2013, 10:00 PM   PM User | #2
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,521
Thanks: 45
Thanked 440 Times in 429 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 01-08-2013, 02:06 PM   PM User | #3
TFlan
New Coder

 
Join Date: Dec 2012
Location: USA
Posts: 82
Thanks: 3
Thanked 17 Times in 17 Posts
TFlan is an unknown quantity at this point
You have the if statement backwards - if the mail fails, do this. if not mail again.

There is a '!'
TFlan is offline   Reply With Quote
Old 01-08-2013, 07:15 PM   PM User | #4
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,521
Thanks: 45
Thanked 440 Times in 429 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 01-08-2013, 07:22 PM   PM User | #5
TFlan
New Coder

 
Join Date: Dec 2012
Location: USA
Posts: 82
Thanks: 3
Thanked 17 Times in 17 Posts
TFlan is an unknown quantity at this point
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
TFlan is offline   Reply With Quote
Old 01-08-2013, 11:06 PM   PM User | #6
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,521
Thanks: 45
Thanked 440 Times in 429 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:44 PM.


Advertisement
Log in to turn off these ads.