gnawz Posted April 30, 2009 Share Posted April 30, 2009 Hi. I have a php email script that sends newsletters to email addresses stored in my db. However, In my email panel, there is an HTML editor so I can do some HTML formatting like bold/italic, etc My problem is users receive emails with text mixed with HTML formatting... things like <span> <br> <em> included in the text. How do I make sure I send only the text without it losing its formatting? Below is my email sending function function sendNL() { $adminmail = "admin@localhost.com"; $path = "localhost"; if(isset($_POST['submit'])) $nletter = $_POST['txtTitle']; $subject = $_POST['txaDescription']; //the block above formats the letter so it will send correctly. $sql="SELECT * from mogas_newsletter order by email ASC"; //select e-mails in ABC order $result=mysql_query($sql) or die("Could not get list"); while($row=mysql_fetch_array($result)) { $headers = "From: $adminmail \r\n"; $headers.= "Content-Type: text/html; charset=ISO-8859-1 "; //send HTML enabled mail $headers .= "MIME-Version: 1.0 "; mail("$row[email]","$subject","$nletter",$headers); } print "Newsletter Sent."; echo "<META HTTP-EQUIV=\"refresh\" content=\"; URL=index.php\"> "; } Quote Link to comment https://forums.phpfreaks.com/topic/156240-email-problem/ Share on other sites More sharing options...
the182guy Posted April 30, 2009 Share Posted April 30, 2009 You haven't put the \r\n at the end of the content-type and mime headers. Each email header needs \r\n at the end of it. Try this: $headers = "From: $adminmail\r\n"; $headers.= "Content-Type: text/html; charset=ISO-8859-1\r\n"; //send HTML enabled mail $headers .= "MIME-Version: 1.0\r\n"; Quote Link to comment https://forums.phpfreaks.com/topic/156240-email-problem/#findComment-822536 Share on other sites More sharing options...
timt Posted April 30, 2009 Share Posted April 30, 2009 Also, remove the "" from the string variables passed to mail(). It cause an extra transformation. Move your headers assignment before the while loop. same headers for every email. Quote Link to comment https://forums.phpfreaks.com/topic/156240-email-problem/#findComment-822663 Share on other sites More sharing options...
gnawz Posted April 30, 2009 Author Share Posted April 30, 2009 The problem is that the email loses its formatting.....ie bold, italics, etc Also images posted are not displayed in the email. Quote Link to comment https://forums.phpfreaks.com/topic/156240-email-problem/#findComment-822686 Share on other sites More sharing options...
the182guy Posted April 30, 2009 Share Posted April 30, 2009 Did you try adding the \r\n ? HTML tags for bold/italics and other formatting will only work if the content-type header is understood to be "text/html". You'll run into problems with images because nearly all email clients will not show images in an email by default. There are ways around it such as attaching all your images to the email. Quote Link to comment https://forums.phpfreaks.com/topic/156240-email-problem/#findComment-822781 Share on other sites More sharing options...
JonnoTheDev Posted April 30, 2009 Share Posted April 30, 2009 You must include a header to tell the email client that the email is in HTML format. See the post above. Also check that your email client is not in plain text. "Content-Type: text/html; charset=ISO-8859-1\r\n" Quote Link to comment https://forums.phpfreaks.com/topic/156240-email-problem/#findComment-822782 Share on other sites More sharing options...
gnawz Posted May 1, 2009 Author Share Posted May 1, 2009 I am sending a test email to a gmail account which receives all sorts of emails, including those with images. I doesn't seem to display the formatting even after I put my header function with text/html Quote Link to comment https://forums.phpfreaks.com/topic/156240-email-problem/#findComment-823755 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.