Jump to content

Email problem


gnawz

Recommended Posts

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\"> ";
}

Link to comment
Share on other sites

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"; 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.