Hey everyone,
I've been trying stuff for a while now, and I just can't find a way to way to fix it.
I have this function to send email to a list of email contained in a MySQL database. The script works fine, BUT the mail() function is really acting weird. There's seem to be problem with POP and hotmail.com addresses ... here's what it does on 2 different server:
On server #1 : NOT the same server as my POP account. When I send a newsletter to lets say 50 people and my POP address is in the list, it successfully gets to all ISPs (hotmail, yahoo etc.) but NOT to my POP.
On server #2 : SAME server as my POP account. When I send a newsletter to the same amount of people with in the list my POP account and some hotmail / fowarding accounts of mine, it ONLY gets to the POP account and NOT the hotmail/fowarding ones, giving me a unrouteable mail domain "hotmail.com" error.
Here's the code:
set_time_limit(0);
ignore_user_abort();
$send_to = array();
// If its a test, send only to admin's email
if ( isset($test) )
{
$send_to[] = $config['admin_email'];
}
// Else send to all registered users
else
{
$newsletter_data = db_select("SELECT `newsletter_email` FROM `newsletter`" );
for ($i = 0; $i < count($newsletter_data); $i++)
{
$send_to[] = $newsletter_data[$i]['newsletter_email'];
}
}
// Fix strings to send in nice HTML
$message = str_replace(array(">", "<", "\"", "&" ), array('>', '<', '"', '&'), $message);
// Check if the user chose TEXT ONLY or HTML.
if ($type_value == 'html')
{
$message = stripslashes($message);
}
else
{
$message = '<font face="arial, verdana, helvetica" size="2">' . stripslashes(nl2br($message)) . '</font>';
}
// Prepare message for the newsletter
$subject = stripslashes($subject);
$object = $config['newsletter_title'] . ' (' . date("m.d.y" ) . '): ' . $subject;
$message = $message . "<br><br>";
// Go through all email in $send_to array and send newsletter
for ($i = 0; $i < count($send_to); $i++)
{
// Add unregister message at the bottom of the message
$unregister_message = 'message';
$headers = "";
//$headers .= "To: $send_to[$i]\n";
$headers .= "From:" . $config['newsletter_sender'] . " <" . $config['newsletter_email'] . ">\n";
$headers .= "Reply-To: " . $config['newsletter_sender'] . " <" . $config['newsletter_email'] . ">\n";
//$headers .= "cc: <$send_to[$i]>\n";
//$headers .= "Bcc: <$send_to[$i]>\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-Mailer: 4.x";
mail($send_to[$i], $object, $message . $unregister_message, $headers);
}
Please help me, I've been searching for a long time now and couldn't find any anwsers to my question.
If you know a stable mass mailing script that runs with MySQL and is easy to customize, please tell me.
Thanks in advance!