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,
php_learner.

<?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 = 'myemail@domain.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>";


}
?>

Try including

X-Mailer: PHP\r\n

in the message header. There could be so many other reasons, but see how you get on with that.

Thanks, but now it gets into yahoo spam instead of inbox

Ouch!Is the email address you're sending from the same as the domain that the script is hosted on?

Just remembered something:

Try 'X-Mailer: PHP '.phpversion().'\r\n'

Thanks, I now have an improvement as it now sends to yahoo and gmail correctly to the inbox. All that is left is one little thing. It is still sending jibberish in outlook. Am assuming it may have to change something in my headers so that it appears as plain text in outlook. Do you have an idea of what i should do?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.