fendert12 fendert12 - 1 year ago 67
PHP Question

I am wondering how to check how many sent emails with mail() + while loop

I am using mail() function to send newsletter to my site users and I used a while loop to sed those emails. The function seems to work fine but I need to check how many mails were really sent so I can compare with my SQL table.

Basically, I have the following function inside a While loop.

$mail_result = mail($leMail, $_POST['sujet'], $_POST['message'], $_POST['email']);

How can I get the count with this $mail_result variable?

Take care ;-)

Answer Source

Most hosting companies have a limit on the number of emails that can be sent per hour. Bluehost for example has a default limit of 150 per hour, per hosting account. Yet if you contact them via support you can up that limit to 750 per hour.

The simplest way based on how you are sending emails is to increment a count based on the mail() response.

I'm not seeing any reference code for a sql query. I'm also unsure of the reason for all the $_POST values in the mail function if you are using a sql while loop. Regardless ...

$cnt = 0;
$sql = "your db query";
While($r = mysql_fetch_array($sql)) { // your sql while loop
    // fetch your sql data and prepare it

    // send the email
    $mail_result = mail($leMail, $_POST['sujet'], $_POST['message'], $_POST['email']);
    IF ($mail_result) { $cnt++; }

echo ("Sent ".$cnt." emails");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download