Problem sending formatted html mail()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wafdenis
    New Member
    • May 2010
    • 2

    #1

    Problem sending formatted html mail()

    Hi,

    I am trying to send html mail() to a number of people at once but it appears as spam in gmail, does not appear in yahoo and appears as jibberish in outlook. I need help in this area as am new to it and am hoping for some correction of where I went wrong or a better php script that can do what I wanted

    Below is my code:

    Thanks,
    Denis.

    Code:
    <?php
    
    if(isset($_POST['submit']))
    
    {
    
      $subject=$_POST['subject'];
    
      $nletter=$_POST['nletter'];
    
      if(strlen($subject)<1)
    
      {
    
         print "You did not enter a subject.";
    
      }
    
      else if(strlen($nletter)<1)
    
      {
    
        print "You did not enter a message.";
    
      }
    
      else
    
      {
          $nletter=$_POST['nletter']; // email content
    
          $nletter = wordwrap($nletter, 70);
    
          $subject=$_POST['subject']; // email subject
    
          $lists=$_POST['lists']; 
    
    
          $SenderEmail = 'info@example.com';
    
    
          $getlist="SELECT * from email_table  order by email ASC"; //select e-mails in ABC order
    
          $getlist2=mysql_query($getlist) or die("Could not get list");
    
          $intelligence = "http://financialacademy.co.ke/blog";
    
          $num = mysql_num_rows($getlist2);          
    
    
    $message .= "<html>";
    $message .= "<head>";
    $message .= "<style type=\"text/css\" media=\"screen\">";
    $message .= "a:link, a:visited {color:#A0C804; text-decoration:none;}";
    $message .= "a:hover {color:#339933; text-decoration:none;}";
    $message .= "body {background-color:#FFFFFF;";
    $message .= "font-family:Arial, Helvetica, sans-serif;";
    $message .= "color:#514f50;";
    $message .= "font-size:10px;}";
    $message .= "p {font-size: 12px;";
    $message .= "line-height: 16px;";
    $message .= "font-weight: normal;";
    $message .= "padding-right:20px;";
    $message .= "padding-left:17px;";
    $message .= "margin-bottom:-5pt;}";
    $message .= "h1 {font-size: 14px;";
    $message .= "line-height: normal;";
    $message .= "font-weight:bold;";
    $message .= "margin-bottom:-5pt;}";
    $message .= ".page {background-color:#ecebeb;";
    $message .= "padding:0px;";
    $message .= "width:570px;}";
    $message .= ".content {width:570px;";
    $message .= "height:auto;";
    $message .= "background-color:#FFFFFF;";
    $message .= "padding:0px;";
    $message .= "border:#ECEBEB;}";
    $message .= ".unsubscribe {width:570px;";
    $message .= "padding-left:0px;";
    $message .= "padding-right:0px;}";
    $message .= ".unsubscribe p{font-size:10px;}";
    $message .= ".smallprint p{font-size: 9px;";
    $message .= "line-height: 16px;";
    $message .= "font-weight: normal;";
    $message .= "padding-right:20px;";
    $message .= "padding-left:17px;";
    $message .= "margin-bottom:-5pt;}";
    $message .= ".style2 {font-size: 30px}";
    $message .= ".style5 {color: #A0C804;";
    $message .= "font-size: 30px;";
    $message .= "font-weight: bold;}";
    $message .= "</style>";
    $message .= "<body>";
    $message .= "<div class=\"page\">";
    $message .= "<div class=\"content\">";
    $message .= "<table width=\"750\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#ECEBEB\">";
    $message .= "<tr>";
    $message .= "<td ><img src=\"http://www.financialacademy.co.ke/admin/images/financia.jpg\" width=\"499px\" height=\"108px\" alt=\"Financial Academy!\" align=\"center\" /></td>";
    $message .= "</tr>";
    $message .= "<tr>";
    $message .= "<td>";
    $message .= "<br>";
    $message .= "<p> $nletter <a href=$intelligence> .Read More.. </a> </p> <br>";
    $message .= "<p><p>To unsubscribe to our Newsletter, click on www.financialacademy.co.ke/unsubscribe.php</p></p>";
    $message .= "</td>";
    $message .= "</tr>";
    $message .= "</table>";
    $message .= "</div>";
    $message .= "</div>";
    $message .= "</body>";
    $message .= "</html>";
    
    
          while($getlist3=mysql_fetch_array($getlist2))
          {
              
            if (is_array($getlist3[email]))
            {
                $to_email_string = implode(', ', $getlist3[email]);
            }
            else {
                $to_email_string = $getlist3[email];
            }
    
             $header .= "From: $SenderEmail \r\n";
             $header .= "Reply-To: Financial Academy <$adminmail> \r\n";
             $header .= "Return-Path: Financial Academy <$adminmail> \r\n";
             $header .= "Organization: Financial Academy & Technologies \r\n";
             $header .= "Content-Type: text/html charset=iso-8859-1 \r\n";
             $header .= "MIME-Version: 1.0  \r\n";
    
          }
    
           mail($to_email_string, $subject,"Hi,"."<p>$message</p>",$header);
    
       }
    
            echo "<center><br><br><font face=Arial size=3 color=black>Thank you. The email has been sent to.$num. recepients <br><br></font><p>";
    
    }
    
    else
    
    {
    
       print "<form action='sendletter.php' method='post'>";
    
       print "Subject:<br>";
    
       print "<input type='text' name='subject' size='20'><br>";
    
       print "Message:<br>";
    
       print "<textarea name='nletter' cols='50' rows='6'></textarea><br>";
    
       print "<input type='submit' name='submit' value='submit'></form>";
    
    
    }
    ?>
    Last edited by Atli; May 23 '10, 02:21 AM. Reason: Added [code] tags.
  • wafdenis
    New Member
    • May 2010
    • 2

    #2
    Originally posted by wafdenis
    Hi,

    I am trying to send html mail() to a number of people at once but it appears as spam in gmail, does not appear in yahoo and appears as jibberish in outlook. I need help in this area as am new to it and am hoping for some correction of where I went wrong or a better php script that can do what I wanted

    Below is my code:

    Thanks,
    Denis.

    Code:
    <?php
    
    if(isset($_POST['submit']))
    
    {
    
      $subject=$_POST['subject'];
    
      $nletter=$_POST['nletter'];
    
      if(strlen($subject)<1)
    
      {
    
         print "You did not enter a subject.";
    
      }
    
      else if(strlen($nletter)<1)
    
      {
    
        print "You did not enter a message.";
    
      }
    
      else
    
      {
          $nletter=$_POST['nletter']; // email content
    
          $nletter = wordwrap($nletter, 70);
    
          $subject=$_POST['subject']; // email subject
    
          $lists=$_POST['lists']; 
    
    
          $SenderEmail = 'info@example.com';
    
    
          $getlist="SELECT * from email_table  order by email ASC"; //select e-mails in ABC order
    
          $getlist2=mysql_query($getlist) or die("Could not get list");
    
          $intelligence = "http://financialacademy.co.ke/blog";
    
          $num = mysql_num_rows($getlist2);          
    
    
    $message .= "<html>";
    $message .= "<head>";
    $message .= "<style type=\"text/css\" media=\"screen\">";
    $message .= "a:link, a:visited {color:#A0C804; text-decoration:none;}";
    $message .= "a:hover {color:#339933; text-decoration:none;}";
    $message .= "body {background-color:#FFFFFF;";
    $message .= "font-family:Arial, Helvetica, sans-serif;";
    $message .= "color:#514f50;";
    $message .= "font-size:10px;}";
    $message .= "p {font-size: 12px;";
    $message .= "line-height: 16px;";
    $message .= "font-weight: normal;";
    $message .= "padding-right:20px;";
    $message .= "padding-left:17px;";
    $message .= "margin-bottom:-5pt;}";
    $message .= "h1 {font-size: 14px;";
    $message .= "line-height: normal;";
    $message .= "font-weight:bold;";
    $message .= "margin-bottom:-5pt;}";
    $message .= ".page {background-color:#ecebeb;";
    $message .= "padding:0px;";
    $message .= "width:570px;}";
    $message .= ".content {width:570px;";
    $message .= "height:auto;";
    $message .= "background-color:#FFFFFF;";
    $message .= "padding:0px;";
    $message .= "border:#ECEBEB;}";
    $message .= ".unsubscribe {width:570px;";
    $message .= "padding-left:0px;";
    $message .= "padding-right:0px;}";
    $message .= ".unsubscribe p{font-size:10px;}";
    $message .= ".smallprint p{font-size: 9px;";
    $message .= "line-height: 16px;";
    $message .= "font-weight: normal;";
    $message .= "padding-right:20px;";
    $message .= "padding-left:17px;";
    $message .= "margin-bottom:-5pt;}";
    $message .= ".style2 {font-size: 30px}";
    $message .= ".style5 {color: #A0C804;";
    $message .= "font-size: 30px;";
    $message .= "font-weight: bold;}";
    $message .= "</style>";
    $message .= "<body>";
    $message .= "<div class=\"page\">";
    $message .= "<div class=\"content\">";
    $message .= "<table width=\"750\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#ECEBEB\">";
    $message .= "<tr>";
    $message .= "<td ><img src=\"http://www.financialacademy.co.ke/admin/images/financia.jpg\" width=\"499px\" height=\"108px\" alt=\"Financial Academy!\" align=\"center\" /></td>";
    $message .= "</tr>";
    $message .= "<tr>";
    $message .= "<td>";
    $message .= "<br>";
    $message .= "<p> $nletter <a href=$intelligence> .Read More.. </a> </p> <br>";
    $message .= "<p><p>To unsubscribe to our Newsletter, click on www.financialacademy.co.ke/unsubscribe.php</p></p>";
    $message .= "</td>";
    $message .= "</tr>";
    $message .= "</table>";
    $message .= "</div>";
    $message .= "</div>";
    $message .= "</body>";
    $message .= "</html>";
    
    
          while($getlist3=mysql_fetch_array($getlist2))
          {
              
            if (is_array($getlist3[email]))
            {
                $to_email_string = implode(', ', $getlist3[email]);
            }
            else {
                $to_email_string = $getlist3[email];
            }
    
             $header .= "From: $SenderEmail \r\n";
             $header .= "Reply-To: Financial Academy <$adminmail> \r\n";
             $header .= "Return-Path: Financial Academy <$adminmail> \r\n";
             $header .= "Organization: Financial Academy & Technologies \r\n";
             $header .= "Content-Type: text/html charset=iso-8859-1 \r\n";
             $header .= "MIME-Version: 1.0  \r\n";
    
          }
    
           mail($to_email_string, $subject,"Hi,"."<p>$message</p>",$header);
    
       }
    
            echo "<center><br><br><font face=Arial size=3 color=black>Thank you. The email has been sent to.$num. recepients <br><br></font><p>";
    
    }
    
    else
    
    {
    
       print "<form action='sendletter.php' method='post'>";
    
       print "Subject:<br>";
    
       print "<input type='text' name='subject' size='20'><br>";
    
       print "Message:<br>";
    
       print "<textarea name='nletter' cols='50' rows='6'></textarea><br>";
    
       print "<input type='submit' name='submit' value='submit'></form>";
    
    
    }
    ?>
    I managed to fix some problems. The only thing that is left is that it's still sending jibberish in outlook. Any ideas?

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hey.

      What exactly does Outlook show? And could you show us the changes you have made? (Or just post the latest version of the code)

      I would recommend you try using one of the free Mailer classes, like PHPMailer or Swift Mailer. They are usually much easier to deal with that the mail function, at least for emails that are more complex than simple text messages.

      Comment

      Working...