Occasionally Get Duplicate Emails from mail()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • robbiesmith79

    Occasionally Get Duplicate Emails from mail()

    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($emai laddress, $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($emailaddr ess, $emailsubject, $msg, $headers);
    }

    $message = "<h2>Hello World</h2>";
    $subject = "Test Email";
    $to = "myemail@addres s.com";

    $fromaddress = "";

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

  • robbiesmith79

    #2
    Re: Occasionally Get Duplicate Emails from mail()

    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($emai laddress, $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($emailaddr ess, $emailsubject, $msg, $headers);
    >
    }
    >
    $message = "<h2>Hello World</h2>";
    $subject = "Test Email";
    $to = "myem...@addres s.com";
    >
    $fromaddress = "";
    >
    for ($x=0; $x<2000; $x++) {
    send_mail($to, $fromaddress, $subject, $message, "html");
    >
    >
    >
    }- Hide quoted text -
    >
    - Show quoted text -

    Comment

    Working...