I have two servers,ServerA & ServerB.ServerA do not support mass mailing while ServerB do support(I have more than 4000 email addresses in MySQL table).
On ServerA I am creating HTML for emails and On ServerB I put script to send emails.I run this code on ServerA
ob_end_clean();
header("Connection: close");
ignore_user_abort(); // optional
ob_start();
echo ('Sending email...');
$size = ob_get_length();
header("Content-Length: $size");
ob_end_flush(); // Will not work
flush(); // Unless both are called !
$postdata = http_build_query(
array(
'subject'=>'Latest Rentals Properties',
'message' => $message //email body html
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = @file_get_contents('http://ServerB.com/send_email.php', false, $context);
if($http_response_header[0]=="HTTP/1.1 404 Not Found"):echo "404";
elseif($http_response_header[0]=="HTTP/1.1 200 OK"):echo "OK";
else "ERROR";
On ServerB.com,send_email.php has this code to send email(I am using class.phpmailer.php)
$subject = $_REQUEST['subject'];
$message1 = $_REQUEST['message'];
$mail->SetFrom("from@ServerB.com", '');
$rs = $oBj->query("SELECT email FROM `crm_test_emails` where is_active = 1 ");
while ( $rw = $oBj->row($rs) ){
$email= $rw['email'];
$message1 = str_replace("########",$email,$message1);
$mail->AddAddress($email, "");
$mail->Subject = $subject;
$mail->MsgHTML($message1);
$mail->Send();
}
My questions are
- One email address getting more than 500 same emails(sending duplicates).
- Email goes directly to spam.
- I do not want any one to see others emails.Right now one email id can see all others to whom i sent email.
I asked questions on priority,first one is more important and so on.. Please guide me where i have issue in code logic.