JazzyB Posted March 20, 2007 Share Posted March 20, 2007 Hi all, I'm having a problem sending email using php mail. The email is designed with tables so I'm using inline CSS styles. Problem is that the styles do not work. It gets displayed as text. Example: <?php $email_temp = '<html> <head> </head> <body> <table style="border:solid; border-color:#AD9090; border-left-width: 4px; border-right-width: 4px; border-top-width: 0px; border-bottom-width: 0px;" width="700" border="0" cellspacing="0" cellpadding="0"> <tr> <td> </td> </tr> </table> </body> </html>'; mail($email, "Newsletter", $email_temp, "From: [email protected]" ); if(mail($email, "Newsletter", $email_temp, "From: [email protected]" )){ echo "The email was successfully sent."; } else { echo "The email was NOT sent."; } ?> This displays the style as text instead of the required borders eg. border-right-width: 4px; border-top-width: 0px; border-bottom-width: 0px;" width="700" border="0" cellspacing="0" cellpadding="0"> Also the email gets sent twice and I know it is because of the if clause but I'm not sure how else to put it. Please help. Quote Link to comment https://forums.phpfreaks.com/topic/43544-solved-inline-css-style-with-php-problems/ Share on other sites More sharing options...
marmite Posted March 20, 2007 Share Posted March 20, 2007 Hey there, I'm pretty new to this, but at a quick glance it looks like you're missing a " - you have "border: solid.... cellpadding="0" - shouldn't there be another one to close the whole style statement? Could this be it? Quote Link to comment https://forums.phpfreaks.com/topic/43544-solved-inline-css-style-with-php-problems/#findComment-211501 Share on other sites More sharing options...
JazzyB Posted March 20, 2007 Author Share Posted March 20, 2007 I wish that could be it, tried it and still the same thing, I'm sure the style is closed with the double quotes correctly. I echoed it with php and the table style displays fine. Also when I send the email normally (without php code) as plain html the table style displays fine (I'm using hotmail to test this). The style displays as text only when I use the mail function. So now I know where the problem is only question is how do I resolve this? Any ideas? Anyone? ??? Quote Link to comment https://forums.phpfreaks.com/topic/43544-solved-inline-css-style-with-php-problems/#findComment-211562 Share on other sites More sharing options...
Kerblam Posted March 20, 2007 Share Posted March 20, 2007 The email is sending twice because this: mail($email, "Newsletter", $email_temp, "From: [email protected]" ); sends the mail, and then your if clause: if(mail($email, "Newsletter", $email_temp, "From: [email protected]" )){ sends it again. The solution is this: $result = mail($email, "Newsletter", $email_temp, "From: [email protected]" ); if ($result) { Quote Link to comment https://forums.phpfreaks.com/topic/43544-solved-inline-css-style-with-php-problems/#findComment-211570 Share on other sites More sharing options...
JazzyB Posted March 21, 2007 Author Share Posted March 21, 2007 Hey Kerblam, Thanks for the help, the email now gets sent once. I'm still having trouble with the CSS styles. The CSS style still shows as text. I'm searching the forum but I still haven't found anything similar to this issue unless theres something I've missed. Quote Link to comment https://forums.phpfreaks.com/topic/43544-solved-inline-css-style-with-php-problems/#findComment-212256 Share on other sites More sharing options...
UTAlan Posted March 21, 2007 Share Posted March 21, 2007 From php.net: // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: [email protected]' . "\r\n"; Then... $result = mail($email, "Newsletter", $email_temp, $headers); Quote Link to comment https://forums.phpfreaks.com/topic/43544-solved-inline-css-style-with-php-problems/#findComment-212261 Share on other sites More sharing options...
JazzyB Posted March 21, 2007 Author Share Posted March 21, 2007 Thank you UTAlan. The styles are now visible. Quote Link to comment https://forums.phpfreaks.com/topic/43544-solved-inline-css-style-with-php-problems/#findComment-212300 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.