By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,238 Members | 1,565 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,238 IT Pros & Developers. It's quick & easy.

Problem sending formatted html mail()

P: 2
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.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. if(isset($_POST['submit']))
  4.  
  5. {
  6.  
  7.   $subject=$_POST['subject'];
  8.  
  9.   $nletter=$_POST['nletter'];
  10.  
  11.   if(strlen($subject)<1)
  12.  
  13.   {
  14.  
  15.      print "You did not enter a subject.";
  16.  
  17.   }
  18.  
  19.   else if(strlen($nletter)<1)
  20.  
  21.   {
  22.  
  23.     print "You did not enter a message.";
  24.  
  25.   }
  26.  
  27.   else
  28.  
  29.   {
  30.       $nletter=$_POST['nletter']; // email content
  31.  
  32.       $nletter = wordwrap($nletter, 70);
  33.  
  34.       $subject=$_POST['subject']; // email subject
  35.  
  36.       $lists=$_POST['lists']; 
  37.  
  38.  
  39.       $SenderEmail = 'info@example.com';
  40.  
  41.  
  42.       $getlist="SELECT * from email_table  order by email ASC"; //select e-mails in ABC order
  43.  
  44.       $getlist2=mysql_query($getlist) or die("Could not get list");
  45.  
  46.       $intelligence = "http://financialacademy.co.ke/blog";
  47.  
  48.       $num = mysql_num_rows($getlist2);          
  49.  
  50.  
  51. $message .= "<html>";
  52. $message .= "<head>";
  53. $message .= "<style type=\"text/css\" media=\"screen\">";
  54. $message .= "a:link, a:visited {color:#A0C804; text-decoration:none;}";
  55. $message .= "a:hover {color:#339933; text-decoration:none;}";
  56. $message .= "body {background-color:#FFFFFF;";
  57. $message .= "font-family:Arial, Helvetica, sans-serif;";
  58. $message .= "color:#514f50;";
  59. $message .= "font-size:10px;}";
  60. $message .= "p {font-size: 12px;";
  61. $message .= "line-height: 16px;";
  62. $message .= "font-weight: normal;";
  63. $message .= "padding-right:20px;";
  64. $message .= "padding-left:17px;";
  65. $message .= "margin-bottom:-5pt;}";
  66. $message .= "h1 {font-size: 14px;";
  67. $message .= "line-height: normal;";
  68. $message .= "font-weight:bold;";
  69. $message .= "margin-bottom:-5pt;}";
  70. $message .= ".page {background-color:#ecebeb;";
  71. $message .= "padding:0px;";
  72. $message .= "width:570px;}";
  73. $message .= ".content {width:570px;";
  74. $message .= "height:auto;";
  75. $message .= "background-color:#FFFFFF;";
  76. $message .= "padding:0px;";
  77. $message .= "border:#ECEBEB;}";
  78. $message .= ".unsubscribe {width:570px;";
  79. $message .= "padding-left:0px;";
  80. $message .= "padding-right:0px;}";
  81. $message .= ".unsubscribe p{font-size:10px;}";
  82. $message .= ".smallprint p{font-size: 9px;";
  83. $message .= "line-height: 16px;";
  84. $message .= "font-weight: normal;";
  85. $message .= "padding-right:20px;";
  86. $message .= "padding-left:17px;";
  87. $message .= "margin-bottom:-5pt;}";
  88. $message .= ".style2 {font-size: 30px}";
  89. $message .= ".style5 {color: #A0C804;";
  90. $message .= "font-size: 30px;";
  91. $message .= "font-weight: bold;}";
  92. $message .= "</style>";
  93. $message .= "<body>";
  94. $message .= "<div class=\"page\">";
  95. $message .= "<div class=\"content\">";
  96. $message .= "<table width=\"750\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#ECEBEB\">";
  97. $message .= "<tr>";
  98. $message .= "<td ><img src=\"http://www.financialacademy.co.ke/admin/images/financia.jpg\" width=\"499px\" height=\"108px\" alt=\"Financial Academy!\" align=\"center\" /></td>";
  99. $message .= "</tr>";
  100. $message .= "<tr>";
  101. $message .= "<td>";
  102. $message .= "<br>";
  103. $message .= "<p> $nletter <a href=$intelligence> .Read More.. </a> </p> <br>";
  104. $message .= "<p><p>To unsubscribe to our Newsletter, click on www.financialacademy.co.ke/unsubscribe.php</p></p>";
  105. $message .= "</td>";
  106. $message .= "</tr>";
  107. $message .= "</table>";
  108. $message .= "</div>";
  109. $message .= "</div>";
  110. $message .= "</body>";
  111. $message .= "</html>";
  112.  
  113.  
  114.       while($getlist3=mysql_fetch_array($getlist2))
  115.       {
  116.  
  117.         if (is_array($getlist3[email]))
  118.         {
  119.             $to_email_string = implode(', ', $getlist3[email]);
  120.         }
  121.         else {
  122.             $to_email_string = $getlist3[email];
  123.         }
  124.  
  125.          $header .= "From: $SenderEmail \r\n";
  126.          $header .= "Reply-To: Financial Academy <$adminmail> \r\n";
  127.          $header .= "Return-Path: Financial Academy <$adminmail> \r\n";
  128.          $header .= "Organization: Financial Academy & Technologies \r\n";
  129.          $header .= "Content-Type: text/html charset=iso-8859-1 \r\n";
  130.          $header .= "MIME-Version: 1.0  \r\n";
  131.  
  132.       }
  133.  
  134.        mail($to_email_string, $subject,"Hi,"."<p>$message</p>",$header);
  135.  
  136.    }
  137.  
  138.         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>";
  139.  
  140. }
  141.  
  142. else
  143.  
  144. {
  145.  
  146.    print "<form action='sendletter.php' method='post'>";
  147.  
  148.    print "Subject:<br>";
  149.  
  150.    print "<input type='text' name='subject' size='20'><br>";
  151.  
  152.    print "Message:<br>";
  153.  
  154.    print "<textarea name='nletter' cols='50' rows='6'></textarea><br>";
  155.  
  156.    print "<input type='submit' name='submit' value='submit'></form>";
  157.  
  158.  
  159. }
  160. ?>
May 22 '10 #1
Share this Question
Share on Google+
2 Replies


P: 2
@wafdenis
I managed to fix some problems. The only thing that is left is that it's still sending jibberish in outlook. Any ideas?
May 24 '10 #2

Atli
Expert 5K+
P: 5,058
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.
May 24 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.