<?php
$list = file('list.txt');
foreach ($list as $line) {
$info = explode(",", $line);
$email = $info[0];
$firstname = $info[1];
$lastnameraw = $info[2];
$lastname = str_replace("\r\n","",$lastnameraw);
$fullname = "$firstname $lastname";
$fromemail = "";
$fromname = "";
$replyto = "";
$header = "From: $fromname <$fromemail>\r\nReply-To: $replyto\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/html\r\n";
$header .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
$header .= "$message\r\n";
$subject = "";
$message = "";
mail($email, $subject, "", $header);
}
?>
How can i make it remember what emails were sent to not resend them and then reconnect and continue?You can use a data base. Make it a "log" table. As each email is sent, add it to the log. Whenever the script has to be restarted, SELECT the already sent emails from the log, and skip sending the email if the log contains an indicator that the message has already been sent.
<?php
$list = "list.txt";
$hosts = "hosts.txt";
$listcount = count(file($list));
$hostscount = count(file($hosts));
$splitnum = (int)($listcount / $hostscount);
$handle = fopen("list.txt", "r");
$currentfile = 1;
$output = FALSE;
if ($list) {
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
if (!$output) {
$output = fopen("list.txt" . ($currentfile++), "w");
$lines = 0;
}
fwrite($output, $buffer);
if (strrchr($buffer,"\n")) {
$complete = TRUE;
++$lines;
if ($lines == $splitnum) {
fclose($output);
$output = FALSE;
}
} else {
$complete = FALSE;
}
}
fclose($handle);
if ($output) {
if (!$complete) {
fwrite($output,"\n");
}
fclose($output);
}
}
echo "$listcount / $hostscount = $splitnum";
$port = 25;
$bccsize = 50;
$mydomain = "mydomain.com";
$fromemail = "";
$fromname = "";
$replyto = "";
$subject = "";
$message = "";
foreach ($hosts as $line) {
$info = explode(",", $line);
$hostname = $info[0];
$username = $info[1];
$password = $info[2];
$lists = fopen("list.txt" . ($currentfile++), "r");
foreach ($lists as $line) {
$info = explode(",", $line);
$email = $info[0];
$firstname = $info[1];
$lastnameraw = $info[2];
$lastname = str_replace("\r\n","",$lastnameraw);
$fullname = "$firstname $lastname";
}
$connect = fsockopen($hostname,$port);
fputs($connect, "EHLO $mydomain\r\n");
fputs($connect, "AUTH LOGIN\r\n");
fputs($connect, base64_encode($username)."\r\n");
fputs($connect, base64_encode($password)."\r\n");
fputs($connect, "FROM:$fromname <$fromemail>\r\nReply-To: $replyto\r\n");
fputs($connect, "RCPT TO:$fullname <$email>\r\n");
fputs($connect, "DATA\r\n");
fputs($connect, "MIME-Version: 1.0\r\n");
fputs($connect, "Content-Type: text/html\r\n");
fputs($connect, "Content-Transfer-Encoding: base64\r\n\r\n");
fputs($connect, "To: $recipient\n");
fputs($connect, "Subject: $subject\n\n");
fputs($connect, "$message\r\n");
fputs($connect, ".\r\n");
fputs($connect, "QUIT\r\n");
}
?>
http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm