gergy008 Posted June 1, 2010 Share Posted June 1, 2010 Ok, I am using the following code to send an email with PHP, And the email is in HTML. Yet PHP keeps sending it in plain text. How do I go about it? Thanks in advance!! $topic="Some subject"; $detail="<html><body><a href="">Some HTML email code</a></body></html>"; $recipent=$_POST["email"]; //This is working, I have tested this already, It does send to the recipent. $headers="From: #####.co.uk <support@#####.co.uk>\n\r"; $headers.="Content-Type: text/html"; $sent=mail($recipent, $topic, $detail, $headers); Link to comment https://forums.phpfreaks.com/topic/203520-html-emails-sent-with-php-mail-are-displayed-in-plain-text/ Share on other sites More sharing options...
shadiadiph Posted June 1, 2010 Share Posted June 1, 2010 use css to style the text but the css has to be in the message too when using css in a message remember to escape all the quotes example color=\"#ff0000\" etc Link to comment https://forums.phpfreaks.com/topic/203520-html-emails-sent-with-php-mail-are-displayed-in-plain-text/#findComment-1066140 Share on other sites More sharing options...
gergy008 Posted June 1, 2010 Author Share Posted June 1, 2010 use css to style the text but the css has to be in the message too when using css in a message remember to escape all the quotes example color=\"#ff0000\" etc Sorry, I must refine this a bit better. Whatever code I try, The reciepent recieves plain text, In HTML form. The recipent actually sees the HTML tags. Say I use this code: <a href="http://www.google.co.uk/">Google</a> in my email, That what the reciepent sees. Not Google or Google. Just <a href="http://www.google.co.uk/">Google</a> Just added an example: Link to comment https://forums.phpfreaks.com/topic/203520-html-emails-sent-with-php-mail-are-displayed-in-plain-text/#findComment-1066144 Share on other sites More sharing options...
The Eagle Posted June 1, 2010 Share Posted June 1, 2010 Whenever I used PHP mail I'd do this and it'd work. // message $message = ' <html> <head> <title>Hi</title> </head> <body> <p>text!</p> </body> </html> '; Link to comment https://forums.phpfreaks.com/topic/203520-html-emails-sent-with-php-mail-are-displayed-in-plain-text/#findComment-1066147 Share on other sites More sharing options...
shadiadiph Posted June 1, 2010 Share Posted June 1, 2010 This is what i use $to = "[email protected]"; $subject = "Subject"; $MsgHeader = "From: websitename <[email protected]> \n"; $MsgHeader .= "MIME-Version: 1.0\n"; $MsgHeader .= "Content-type: text/html; charset=iso-8859-1"; $MsgBody = " <html> <head> <style type=\"text/css\"> table.logo{ width: 100%; height: auto; text-align: left; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; } table.main{ width: 100%; height: auto; } table.main td{ width: auto; height: auto; text-align: left; font-size: 13px; font-family: tahoma, arial; font-weight: normal; color: #333; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 15px; } table.footer{ width: 100%; height: auto; } table.footer td{ width: auto; height: auto; text-align: left; font-size: 10px; font-family: tahoma, arial; font-weight: normal; color: #336699; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 15px; } </style> <title>HTML message</title> </head> <body> <table class=\"logo\"> <tr><td><img src=\"http://www.website.com/pix/logo.png\"></td></tr> </table> <table class=\"main\"> <tr><td> </td></tr> <tr><td> </td></tr> <tr><td>Dear John,</td></tr> <tr><td> </td></tr> <tr><td>Welcome</td></tr> <tr><td> </td></tr> <tr><td>Thank you for</td></tr> <tr><td> </td></tr> <tr><td>username: user</td></tr> <tr><td>password: pass</td></tr> <tr><td> </td></tr> <tr><td>Text 2</td></tr> <tr><td><a href=\"http://www.website.com\">website.com</a></td></tr> <tr><td> </td></tr> <tr><td>Regards</td></tr> <tr><td> </td></tr> <tr><td>Website Team</td></tr> <tr><td> </td></tr> <tr><td>Additional Message</td></tr> <tr><td> </td></tr> <tr><td> </td></tr> </table> <table class=\"footer\"> <tr><td>Disclaimer </td></tr> </table> </body> </html>"; mail($to, $subject, $MsgBody, $MsgHeader); Link to comment https://forums.phpfreaks.com/topic/203520-html-emails-sent-with-php-mail-are-displayed-in-plain-text/#findComment-1066153 Share on other sites More sharing options...
gergy008 Posted June 1, 2010 Author Share Posted June 1, 2010 This is what i use $to = "[email protected]"; $subject = "Subject"; $MsgHeader = "From: websitename <[email protected]> \n"; $MsgHeader .= "MIME-Version: 1.0\n"; $MsgHeader .= "Content-type: text/html; charset=iso-8859-1"; $MsgBody = " <html> <head> <style type=\"text/css\"> table.logo{ width: 100%; height: auto; text-align: left; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; } table.main{ width: 100%; height: auto; } table.main td{ width: auto; height: auto; text-align: left; font-size: 13px; font-family: tahoma, arial; font-weight: normal; color: #333; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 15px; } table.footer{ width: 100%; height: auto; } table.footer td{ width: auto; height: auto; text-align: left; font-size: 10px; font-family: tahoma, arial; font-weight: normal; color: #336699; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 15px; } </style> <title>HTML message</title> </head> <body> <table class=\"logo\"> <tr><td><img src=\"http://www.website.com/pix/logo.png\"></td></tr> </table> <table class=\"main\"> <tr><td> </td></tr> <tr><td> </td></tr> <tr><td>Dear John,</td></tr> <tr><td> </td></tr> <tr><td>Welcome</td></tr> <tr><td> </td></tr> <tr><td>Thank you for</td></tr> <tr><td> </td></tr> <tr><td>username: user</td></tr> <tr><td>password: pass</td></tr> <tr><td> </td></tr> <tr><td>Text 2</td></tr> <tr><td><a href=\"http://www.website.com\">website.com</a></td></tr> <tr><td> </td></tr> <tr><td>Regards</td></tr> <tr><td> </td></tr> <tr><td>Website Team</td></tr> <tr><td> </td></tr> <tr><td>Additional Message</td></tr> <tr><td> </td></tr> <tr><td> </td></tr> </table> <table class=\"footer\"> <tr><td>Disclaimer </td></tr> </table> </body> </html>"; mail($to, $subject, $MsgBody, $MsgHeader); In your headers, You used \n, Is it because I am using \r\n?? Link to comment https://forums.phpfreaks.com/topic/203520-html-emails-sent-with-php-mail-are-displayed-in-plain-text/#findComment-1066155 Share on other sites More sharing options...
shadiadiph Posted June 1, 2010 Share Posted June 1, 2010 i doubt it no char encoding or mime type Link to comment https://forums.phpfreaks.com/topic/203520-html-emails-sent-with-php-mail-are-displayed-in-plain-text/#findComment-1066158 Share on other sites More sharing options...
gergy008 Posted June 1, 2010 Author Share Posted June 1, 2010 i doubt it no char encoding or mime type Well I am now using your headers and now I get the email in HTML... But nothing is in it... Code: $subject="Some subject"; $detail=" <html> <body bgcolor=\"#000000\" style=\"text-align:center\"> <font color=\"#FFFFFF\" face=\"Myriad Pro, Century Gothic, Arial, serif\">Epic fail.</font> </body> </html>"; $recipent=$_POST["email"]; $headers = "From: #####.co.uk <support@#####.co.uk>\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-type: text/html; charset=iso-8859-1"; $sent=mail($recipent, $subject, $detail, $headers); Link to comment https://forums.phpfreaks.com/topic/203520-html-emails-sent-with-php-mail-are-displayed-in-plain-text/#findComment-1066162 Share on other sites More sharing options...
shadiadiph Posted June 1, 2010 Share Posted June 1, 2010 i just tried this as a test and got it fine not sure if a font like Myriad Pro will work with email as I have never heard of it <?php $to = "[email protected]"; $subject = "Subject"; $MsgHeader = "From: websitename <[email protected]> \n"; $MsgHeader .= "MIME-Version: 1.0\n"; $MsgHeader .= "Content-type: text/html; charset=iso-8859-1"; $MsgBody = " <html> <head> <style type=\"text/css\"> .messagetext{ width: 100%; height: auto; text-align: left; color: #fff; font-size: 13px; font-family: tahoma, arial; background: #000; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; } </style> <title>HTML message</title> </head> <body> <span class=\"messagetext\">Epic Fail</span> </body> </html>"; $send = mail($to, $subject, $MsgBody, $MsgHeader); if ($send==true){ echo "sent"; } else { echo "not sent"; } ?> Link to comment https://forums.phpfreaks.com/topic/203520-html-emails-sent-with-php-mail-are-displayed-in-plain-text/#findComment-1066166 Share on other sites More sharing options...
shadiadiph Posted June 1, 2010 Share Posted June 1, 2010 or use it like this just to style the body <?php $to = "[email protected]"; $subject = "Subject"; $MsgHeader = "From: websitename <[email protected]> \n"; $MsgHeader .= "MIME-Version: 1.0\n"; $MsgHeader .= "Content-type: text/html; charset=iso-8859-1"; $MsgBody = " <html> <head> <style type=\"text/css\"> body{ width: 100%; height: auto; text-align: center; color: #fff; font-size: 13px; font-family: tahoma, arial; background: #000; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; } </style> <title>HTML message</title> </head> <body> Epic Fail </body> </html>"; $send = mail($to, $subject, $MsgBody, $MsgHeader); if ($send==true){ echo "sent"; } else { echo "not sent"; } ?> Link to comment https://forums.phpfreaks.com/topic/203520-html-emails-sent-with-php-mail-are-displayed-in-plain-text/#findComment-1066169 Share on other sites More sharing options...
riwan Posted June 1, 2010 Share Posted June 1, 2010 $headers="From: #####.co.uk <support@#####.co.uk>\n\r"; shouldn't you use below ? $headers="From: #####.co.uk <support@#####.co.uk>\r\n"; Other errors I noted is this $detail="<html><body><a href="">Some HTML email code</a></body></html>"; should be this $detail="<html><body><a href=\"\">Some HTML email code</a></body></html>"; Link to comment https://forums.phpfreaks.com/topic/203520-html-emails-sent-with-php-mail-are-displayed-in-plain-text/#findComment-1066179 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.