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

Occasionally Get Duplicate Emails from mail()

P: n/a
I'm trying to spam myself :-\ with 2,000 emails, shooting for 15,000,
and I will occasionally get two identical emails. I'm putting a
$counter++ as the from and part of the subject line so I can see
what's going on. Any reason why this might happen? here's my code just
in case.

$counter=1;

function send_mail($emailaddress, $fromaddress, $emailsubject, $body,
$method) {
global $counter;

# Common Headers
if ($method == "text") {
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-MSMail-Priority: Normal\n";
$headers .= "X-Mailer: php\n";
} elseif ($method == "html") {
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-MSMail-Priority: Normal\n";
$headers .= "X-Mailer: php\n";
}

$from = $counter++;

$headers .= 'From: Me <'. $from . '@gmail.com>';
$msg = $body;
$msg = wordwrap($msg, 70);

$emailsubject .= " :: " . $from;

# SEND THE EMAIL
mail($emailaddress, $emailsubject, $msg, $headers);
}

$message = "<h2>Hello World</h2>";
$subject = "Test Email";
$to = "my*****@address.com";

$fromaddress = "";

for ($x=0; $x<2000; $x++) {
send_mail($to, $fromaddress, $subject, $message, "html");
}

Jul 5 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Ok. aside from the wierdness that outlook received the same email
twice (got 4,000 in my inbox) my gmail account gladly swollowed the
2,000 correctly. But after further thought on my problem, I'm going to
say that PHP buffered all the requests to mail, and the counter
function wasn't keeping up with my global counter so it looked like I
was getting duplicate emails. When PHP got around to processing the
actual mail, the counter had already up'ed itself and simply said
"ok".

Flaky.

On Jul 5, 10:46 am, robbiesmith79 <robbiesmit...@gmail.comwrote:
I'm trying to spam myself :-\ with 2,000 emails, shooting for 15,000,
and I will occasionally get two identical emails. I'm putting a
$counter++ as the from and part of the subject line so I can see
what's going on. Any reason why this might happen? here's my code just
in case.

$counter=1;

function send_mail($emailaddress, $fromaddress, $emailsubject, $body,
$method) {
global $counter;

# Common Headers
if ($method == "text") {
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-MSMail-Priority: Normal\n";
$headers .= "X-Mailer: php\n";
} elseif ($method == "html") {
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-MSMail-Priority: Normal\n";
$headers .= "X-Mailer: php\n";
}

$from = $counter++;

$headers .= 'From: Me <'. $from . '...@gmail.com>';
$msg = $body;
$msg = wordwrap($msg, 70);

$emailsubject .= " :: " . $from;

# SEND THE EMAIL
mail($emailaddress, $emailsubject, $msg, $headers);

}

$message = "<h2>Hello World</h2>";
$subject = "Test Email";
$to = "myem...@address.com";

$fromaddress = "";

for ($x=0; $x<2000; $x++) {
send_mail($to, $fromaddress, $subject, $message, "html");

}- Hide quoted text -

- Show quoted text -

Jul 5 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.