Jump to content

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
https://forums.phpfreaks.com/topic/156240-email-problem/
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
https://forums.phpfreaks.com/topic/156240-email-problem/#findComment-822536
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
https://forums.phpfreaks.com/topic/156240-email-problem/#findComment-822781
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.