PHP_TRY_HARD Posted March 5, 2009 Share Posted March 5, 2009 I am having lots and lots of trouble! When I send the PHP mail everything works fine except the Text comes through with all the html tags. How can I have it email trough as a nice html email message. I need to pimp my email with a bold font and logo etc. Below is the code. Please help!! :'( //Start Message $message = " <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>You Have Contacted *********</title> </head> <body> <p><font face=arial size=2><strong>Dear $Name</strong>,</p> <font face=arial size=2><p>Thank you for contacting *******, we appreciate your comments. An ******** representative will be in contact with you within the next 2 business days.<br><br>The safe collection of your information and your privacy are important to us, as such please visit <a href=http://www.**********.com.au/>www.**********.com.au</a> to view our privacy policy in full.<br><br> Your Enquiry number is: <strong>#$enq_num </strong><br>Date Submitted $dt <br> Please Keep this number for future reference.<br> </p> <font face=arial size=2><p>Please check your details below for accuracy.</p></font> <font face=arial size=2><strong>Name:</strong> $Name <br></font> <font face=arial size=2><strong>Email Address:</strong> $email<br></font> <font face=arial size=2><strong>Address:</strong> $Address<br></font> <font face=arial size=2><strong>Postcode:</strong> $postcode<br></font> <font face=arial size=2><strong>User Comments:</strong><br>$User_Comments<br><br><br></font> <hr noshade color=gray><br> <font face=arial size=2> If you wish to change these details, please email us at<br> <a href=mailto:info@*******.net.au>info@******.net.au</a> with your request.<br><br> Please print this information and store it for future reference.<br><br> Yours Sincerely, <p><strong>***** ********<br> ** - Marketing and Public Relations</strong><br>**********<br><font color=gray> Phone: (00) 0000 0000 <font color=red>|</font> Fax:(00) 0000 00000<br>0111 ***************** Road **********</p><br></font> <img src=http://www.zzzzzzzzzzzzz.com.au/date.png><br><br><img src=http://www.xxxxxxxxxxx.com.au/logozzzzz/logo.png><br> </body> </html> "; //End Message $to = "info@********.net.au"; // Always set content-type when sending HTML email $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= "From: $yoursite <$youremail>\r\n"; $headers .= "Reply-To: info@*********.net.au\r\n"; $headers .= "Return-Path: info@*********.net.au\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; //Mail the thing mail($email, $subject, $message, $headers); mail($to, $subject, $message, $headers); mysql_close(); header( "Location: $thankyouurl" ); exit(); /*if(mail($to, $subject, $message, $headers)){ echo "success=true"; }else{ echo "success=false"; } */ ?> Quote Link to comment https://forums.phpfreaks.com/topic/148025-php-mail-with-html-message-problem/ Share on other sites More sharing options...
phpdragon Posted March 5, 2009 Share Posted March 5, 2009 the first line of message needs to be $message="blah blah"; then every other line you enter needs to be $message=."blah blah"; Quote Link to comment https://forums.phpfreaks.com/topic/148025-php-mail-with-html-message-problem/#findComment-776974 Share on other sites More sharing options...
PHP_TRY_HARD Posted March 5, 2009 Author Share Posted March 5, 2009 Thank you for the super quick reply, should I put the tags on their own line? Is this correct? Thank you once again. //Start Message $message = "<html>" $message = "<head>" $message = "<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />" $message = "</head>" $message = "<body>" Quote Link to comment https://forums.phpfreaks.com/topic/148025-php-mail-with-html-message-problem/#findComment-776987 Share on other sites More sharing options...
phpdragon Posted March 5, 2009 Share Posted March 5, 2009 correct aswell as <table> <tr> <td> </tr> </table> this method has always worked for me Quote Link to comment https://forums.phpfreaks.com/topic/148025-php-mail-with-html-message-problem/#findComment-777021 Share on other sites More sharing options...
PHP_TRY_HARD Posted March 5, 2009 Author Share Posted March 5, 2009 Thanks, When I used the multipul "$message" it would't even send the mail. I cut the cod down to the bare mininmum and it still wouldn't send. Any Ideas? //Start Message $message = "<html>" $message = "<body>" $message = "<p><font face=arial size=2><strong>Dear $Name</strong>,</p>" $message = "</body>" $message = "</html>"; Quote Link to comment https://forums.phpfreaks.com/topic/148025-php-mail-with-html-message-problem/#findComment-777056 Share on other sites More sharing options...
WolfRage Posted March 5, 2009 Share Posted March 5, 2009 This is wrong. <?php $message = "<html>" $message = "<body>" $message = "<p><font face=arial size=2><strong>Dear $Name</strong>,</p>" $message = "</body>" $message = "</html>"; ?> Do like this. <?php $message = '<html>'; $message =.'<body>'; $message =.'<p><font face="arial" size="2"><strong>Dear '.$Name.'</strong>,</p>'; $message =.'</body>'; $message =.'</html>'; ?> The =. appends to the string, where as = replaces the string. Also using all of those double qoutes is putting php in eval mode, which takes longer to process. Make sure you don't do this: <?php $message = "<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />" ?> You effectively stoped writing to your string when you used double qoutes before you were done. You have to open and close with the same type of qoutes, preferably single qoutes unless you have a variable. Like so: <?php $message = '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />; //if you have a variable do it like this $message = '<meta http-equiv="Content-Type" content="'.$content.'; charset=iso-8859-1" />'; ?> Finaly Do not forget your semi colons ( ; ) Quote Link to comment https://forums.phpfreaks.com/topic/148025-php-mail-with-html-message-problem/#findComment-777070 Share on other sites More sharing options...
phpdragon Posted March 5, 2009 Share Posted March 5, 2009 he missed the '.' in front of every line after the first in my comment, then I didnt pick up on what he typed back, I had only noticed he picked up on what I meant about breaking the lines up. Quote Link to comment https://forums.phpfreaks.com/topic/148025-php-mail-with-html-message-problem/#findComment-777142 Share on other sites More sharing options...
PHP_TRY_HARD Posted March 9, 2009 Author Share Posted March 9, 2009 Thank you both for your help once again, I have tried to emulate your code but it still isn't working. is this legal? $message .= ''.$email.''; Here is the code that I tried to fix. //Start Message $message = '<html>'; $message .= '<body>'; $message .= '<p><font face="arial" size="2"><strong>Dear '.$Name.'</strong>,</p>'; $message .= '<font face="arial" size="2">'; $message .= '<p>'; $message .= 'Thank you for contacting Client, we appreciate your comments.'; $message .= ' An Client representative will be in contact with you within the next 2 business days.'; $message .= '<br>'; $message .= '<br>'; $message .= 'The safe collection of your information and your privacy are important to us, as such please visit'; $message .= '<a href="http://www.client.com.au/">www.client.com.au</a> to view our privacy policy in full.'; $message .= '<br>'; $message .= '<br>'; $message .= 'Your Enquiry number is:'; $message .= '<strong>'; $message .= ''.$enq_num.''; $message .= '</strong>'; $message .= '<br>'; $message .= 'Date Submitted'; $message .= ''.$dt.''; $message .= '<br>'; $message .= 'Please Keep this number for future reference.'; $message .= '<br>'; $message .= '</p>'; $message .= '<font face="arial" size="2"><p>Please check your details below for accuracy.</p></font>'; $message .= '<font face="arial" size="2"><strong>Name:</strong>'; $message .= ''.$Name.''; $message .= '<br>'; $message .= '</font>'; $message .= '<font face="arial" size="2"><strong>Email Address:</strong>'; $message .= ''.$email.''; $message .= '<br>'; $message .= '</font>'; $message .= '<font face="arial" size="2"><strong>Address:</strong>'; $message .= ''.$Address.''; $message .= '<br>'; $message .= '</font>'; $message .= '<font face="arial" size="2"><strong>Postcode:</strong>'; $message .= ''.$postcode.''; $message .= '<br>'; $message .= '</font>'; $message .= '<font face="arial" size="2"><strong>User Comments:</strong>'; $message .= '<br>'; $message .= ''.$User_Comments.''; $message .= '<br>'; $message .= '<br>'; $message .= '</font>'; $message .= '<hr noshade color="gray">'; $message .= '<br>'; $message .= '<font face="arial" size="2"> If you wish to change these details, please email us at'; $message .= '<br>' $message .= '<a href="mailto:[email protected]">[email protected]</a> with your request.'; $message .= '<br>'; $message .= '<br>'; $message .= 'Please print this information and store it for future reference.'; $message .= '<br>'; $message .= '<br>'; $message .= 'Yours Sincerely,'; $message .= '<p>'; $message .= '<strong>client'; $message .= '<br>'; $message .= 'GM - clinet</strong>'; $message .= '<br>'; $message .= 'client'; $message .= '<br>'; $message .= '<font color="gray">'; $message .= 'Phone: (07) 3113 5888'; $message .= '<font color="red">|</font> Fax:(07) 0000 8888'; $message .= '<br>'; $message .= 'address, address</p>'; $message .= '<br>'; $message .= '</font>'; $message .= '<br>'; $message .= '<img src="http://www.client.com.au/client/logo.png">'; $message .= '<br>'; $message .= '</body>'; $message .= '</html>'; //End Message Quote Link to comment https://forums.phpfreaks.com/topic/148025-php-mail-with-html-message-problem/#findComment-780049 Share on other sites More sharing options...
shortj75 Posted March 9, 2009 Share Posted March 9, 2009 this is a simple html email i use and it work for me and it works great and really simple here is the mail form mail.php <form method="post" action="mail2.php"> <table width=100% height=100% cellspacing=0 cellpadding=5 bgcolor=lightblue valign=top><td> To: <input type=text name=to size=30 style="border-width:0px;"> <br> From: <input type=text name=from style="border-width:0px;"> <br> Subject: <input type=text name=sub size=60 style="border-width:0px;"><br> <br> Messege:<br> <textarea name=mess cols=100 rows=20 style="border-width:0px;"></textarea><br> <br> <input type=submit value=send> </td></tr></table></form> and her is the php code to send it $to=$_POST['to']; $mess=$_POST['mess']; $my_subject=$_POST['sub']; $messege="$_POST['mess']"; $my_headers ="MIME-Version: 1.0\r\n"; $my_headers.="Content-type: text/html; charset=iso-8859-1\r\n"; $my_headers.="From: $_POST[from]"; $mail=mail("$to", "$my_subject", "$messege", "$my_headers"); if(!$mail){ print "<center>Sorry Your E-mail Was Not Sent</center>"; }else{ print "<center>Your E-mail Was Sent Successfuly</center>"; } hopefully this helps and if it doesnt i am sorry Quote Link to comment https://forums.phpfreaks.com/topic/148025-php-mail-with-html-message-problem/#findComment-780116 Share on other sites More sharing options...
PHP_TRY_HARD Posted March 9, 2009 Author Share Posted March 9, 2009 Thanks, but the code I am using has lots of funtions on it and I can get it to post but just haveing issues with the email coming out without the HTML formatting. But might use your script in future projects. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/148025-php-mail-with-html-message-problem/#findComment-780119 Share on other sites More sharing options...
PHP_TRY_HARD Posted March 10, 2009 Author Share Posted March 10, 2009 Its working now because I forgot a ";" but now it is showing up in my email with all the tags. a snippets is below html><body><p><font face="arial" size="2"><strong>Dear TESTER</strong>,</p><font face="arial" size="2"><p>Thank you for contacting client, we appreciate your comments. An client representative will be in contact with you within the Any one know what Im doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/148025-php-mail-with-html-message-problem/#findComment-780845 Share on other sites More sharing options...
WolfRage Posted March 10, 2009 Share Posted March 10, 2009 Are you using htmlspecialchars() on the message after you have added the html? Quote Link to comment https://forums.phpfreaks.com/topic/148025-php-mail-with-html-message-problem/#findComment-780919 Share on other sites More sharing options...
PHP_TRY_HARD Posted March 10, 2009 Author Share Posted March 10, 2009 No what is "htmlspecialchars() " how do I use them? And I appreciate the help, thank you Quote Link to comment https://forums.phpfreaks.com/topic/148025-php-mail-with-html-message-problem/#findComment-780946 Share on other sites More sharing options...
WolfRage Posted March 10, 2009 Share Posted March 10, 2009 No I was making sure that you were not using it, because it would convert all of the Tags and that would be bad. However you should use htmlspecialchars() on the user input before you insert it into your message to prevent a malicious user from injecting links and other tags. But I did notice that your snippet said: html><body><p> Make sure that it actually starts like: <html><body> and ends with </body></html> . Other than that every thing looks like it should be working. Quote Link to comment https://forums.phpfreaks.com/topic/148025-php-mail-with-html-message-problem/#findComment-781039 Share on other sites More sharing options...
phpdragon Posted March 12, 2009 Share Posted March 12, 2009 did you get this sorted if not post your full mail form to have a look at Quote Link to comment https://forums.phpfreaks.com/topic/148025-php-mail-with-html-message-problem/#findComment-782915 Share on other sites More sharing options...
kev wood Posted March 12, 2009 Share Posted March 12, 2009 for a start i have never had to put all the head and html tags in to get it to display as an html page when sending emails from a php script. and secondly i have never had to put message at the beginning of every line concatenated or not. here is a script i am using at the minute which retrieves all the email address from a mysql db and sends out an email to each address when my web page is updated. $message .= '<body leftmargin="0" topmargin="0"> <table width="700" border="0" align="center" cellpadding="0" cellspacing="5"> <tr> <td>The ' . $table . ' section of the <a href="piponline.info"> PiPonline website</a> has been updated. Please follow the link to see the new content. </tr> </table> </body>'; $query = "SELECT * FROM emails WHERE page = '$table'"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { $contactemail = $row['email']; // Contacts //$replyName = $merc_replyId; //$replyEmail = $merc_replyAddress; $replyName = "xxxxxx"; $replyEmail = "xxxxxxxx"; $contactname = ""; // Subject $subject = "Website Update"; // Headers $headers = "MIME-Version: 1.0" . PHP_EOL; $headers .= "Content-type: text/html; charset=iso-8859-1" . PHP_EOL; $headers .= "From: ".$replyName." <".$replyEmail.">" . PHP_EOL; $headers .= "BCC: ".$contactname." <".$contactemail.">\r\n" . PHP_EOL; mail($contactemail, $subject, $message, $headers); } where i have this $message .= ' in my script is the start of the email body you can put anything after this in html format and it will display as you like. to end the message body just simply end the last body tag a show in the script above and all should work fine anywhere you would like to have php variables showing up on the page you must format them as follows ' . $table . ' for them to show up correctly. also remember as it is an email if you want to have any images in there being pulled from your server they will need the absolute file reference for it show correctly so it would look some thing like http://www.yoursite.com/images/image_you_want.gif i know the html section of this is not very big but if you would like me to post one which has all the bells an whistles just ask and i will. Quote Link to comment https://forums.phpfreaks.com/topic/148025-php-mail-with-html-message-problem/#findComment-782957 Share on other sites More sharing options...
cigardude Posted March 13, 2009 Share Posted March 13, 2009 Kev wood, if you would not mind posting that I for one would appreeciate it. I am in the begining of the design of my site and I am checking out all of the examples that I can. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/148025-php-mail-with-html-message-problem/#findComment-783917 Share on other sites More sharing options...
PHP_TRY_HARD Posted March 19, 2009 Author Share Posted March 19, 2009 Thanks I will give it a go. I kind of gave up because I lost all my hair pulling it out but it's time I gave it another go. Quote Link to comment https://forums.phpfreaks.com/topic/148025-php-mail-with-html-message-problem/#findComment-788192 Share on other sites More sharing options...
markjoe Posted March 19, 2009 Share Posted March 19, 2009 The most common reason for this, I believe, is bad headers. shortj75 nailed it already, that post contains everything you need to send HTML email. (however, this: $to=$_POST['to']; is a wide open door to become a spam relay, please don't do that on the internet) check your headers at the client by viewing the raw source of the email. Quote Link to comment https://forums.phpfreaks.com/topic/148025-php-mail-with-html-message-problem/#findComment-788242 Share on other sites More sharing options...
mateomtb Posted March 31, 2009 Share Posted March 31, 2009 (however, this: $to=$_POST['to']; is a wide open door to become a spam relay, please don't do that on the internet) Do you have any links to alternatives to avoid the spam potential? I knew this could be a problem and I have finished my app locally and want to seal this part up before it's live. Any suggestions or links to? Quote Link to comment https://forums.phpfreaks.com/topic/148025-php-mail-with-html-message-problem/#findComment-797439 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.