salman_ahad@yahoo.com Posted November 30, 2009 Share Posted November 30, 2009 I am trying to send email using mail() function. I want to be able to include the css style in message too. My present code is <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style> .style1 { color: #777777; } .style2 { color: #666666; } </style> </head> </html> <?php $to = "xyz@mysite.com"; $subject = "promotion"; $message = '' . '<table width="520" border="0" bordercolor="#FFFFFF">' . ' <tr>' . ' <td width="514" height="90"><p> </p>' . ' <p><span class="style1">Reach out to Community!! </span></p>' . ' <span class="style2">1. Click the mail below.</span><br /><br /> </td>' . ' </tr>' . '</table>'; mail($to, $subject, $message); ?> Quote Link to comment https://forums.phpfreaks.com/topic/183359-how-to-insert-style-in-php/ Share on other sites More sharing options...
MadTechie Posted November 30, 2009 Share Posted November 30, 2009 Your need to send your email as HTML, Quote Link to comment https://forums.phpfreaks.com/topic/183359-how-to-insert-style-in-php/#findComment-967835 Share on other sites More sharing options...
Cosizzle Posted November 30, 2009 Share Posted November 30, 2009 You can put the style within your $message. Something that I've come to do is include a php script. MAIL SCRIPT <?php $to = "xyz@mysite.com"; $subject = "promotion"; include('emailToSend.html'); mail($to, $subject, $message); ?> $body in mail <?php $body = " <html> <head> <style type='text/css'> .style1 { color: #777777; } .style2 { color: #666666; } </style> </head> <body> . '<table width="520" border="0" bordercolor="#FFFFFF">' . ' <tr>' . ' <td width="514" height="90"><p> </p>' . ' <p><span class="style1">Reach out to Community!! </span></p>' . ' <span class="style2">1. Click the mail below.</span><br /><br /> </td>' . ' </tr>' . '</table>'; </body> </html>"; ?> edit: I copied your stuff into the second script... so it wont work because of the quotes but you get the idea... Quote Link to comment https://forums.phpfreaks.com/topic/183359-how-to-insert-style-in-php/#findComment-967873 Share on other sites More sharing options...
salman_ahad@yahoo.com Posted December 1, 2009 Author Share Posted December 1, 2009 so I am sending the mail in html form, what am I missing...whats wrong? <?php require('includes/connection.php'); $to_email = 'mohammed.ahad@gmail.com'; $subject = 'How to forward Islamic emails'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style type="text/css"> .style1 {color: #990000} .style2 { color: #000033; font-weight: bold; } .style3 { color: #003300; font-weight: bold; } .style4 { color: #993300; font-weight: bold; } .style5 {color: #000000} .style6 {color: #000000; font-weight: bold; } .style7 {color: #333333} </style> </head> <body> <?php $message = '' .'<table width="520" border="0">' . '<tr>' . '<td width="514"><img src="http://www.ideatoceo.com/emails/kalima.gif" width="514" height="89" longdesc="http://shetech.ideatoceo.com" /></td>' . '</tr>' . '<tr>' . '<td>' .'<table width="512" border="0">' . '<tr>' . '<td width="251" al> <div align="center"><span class="style7">Group of professionals are now ready to train muslims FREE</span></div>' . '<p> <span class="style2">PHP</span> <br /> <span class="style3">MySQL</span><br /> <span class="style4">Web Services <span class="style5">& more</span></span><span class="style6">...</span></p>' . '<p align="center" class="style1">Work on live projects and get trained!' . '</td>' . '<td width="251"><img src="http://www.ideatoceo.com/emails/training.gif" width="205" height="204" align="right" longdesc="http://shetech.ideatoceo.com" /></td>' . '</tr>' .'</table>' . '</td>' . '</tr>' . '<tr>' . '<td><label><label><img src="http://www.ideatoceo.com/emails/Bottom2.gif" width="514" height="48" longdesc="http://shetech.ideatoceo.com" /></label></label></td>' . '</tr>' .'</table>' .'<table>' .'Forwarding Hadith to friends is now easy, visit <a href="http://www.ideatoceo.com/islam-emails.php" target="_blank">IdeatoCEO </a><br />' .'<a href="http://www.ideatoceo.com/islam/emails.php" target="_blank">Unsubscribe</a> from the distribution<br />' . '<br />' .'www.ideatoceo.com | 192 allen ave | Saint Louis | MO | 63104 <br />' .'</table>'; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= "X-Priority: 1 (Higuest)\n"; $headers .= "X-MSMail-Priority: High\n"; $headers .= "Importance: High\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: islam@ideatoceo.com' . "\r\n"; mail($to_email, $subject, $message, $headers); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/183359-how-to-insert-style-in-php/#findComment-968717 Share on other sites More sharing options...
trq Posted December 1, 2009 Share Posted December 1, 2009 Your missing everything before the <body> tags for starters. Quote Link to comment https://forums.phpfreaks.com/topic/183359-how-to-insert-style-in-php/#findComment-968777 Share on other sites More sharing options...
salman_ahad@yahoo.com Posted December 2, 2009 Author Share Posted December 2, 2009 I did not get you... What should I do to above code to accept the styles too? Quote Link to comment https://forums.phpfreaks.com/topic/183359-how-to-insert-style-in-php/#findComment-969426 Share on other sites More sharing options...
salman_ahad@yahoo.com Posted December 2, 2009 Author Share Posted December 2, 2009 Ok I fixed it... I had to insert the style color and size in the <td> tags itself Quote Link to comment https://forums.phpfreaks.com/topic/183359-how-to-insert-style-in-php/#findComment-969438 Share on other sites More sharing options...
MadTechie Posted December 2, 2009 Share Posted December 2, 2009 Was probably a good move, including the styling info IN the email to be applied! Quote Link to comment https://forums.phpfreaks.com/topic/183359-how-to-insert-style-in-php/#findComment-969442 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.