There´s another post about this, over 3 months old, but there they are dealing with port settings which isn´t the problem, so I´m making a new thread.

I send out 50+ emails in a loop via PHPMailer - SMTP.
For testing purposes I send them all to myself, so I can verify receiving them.
I guess I don´t have to post the code, it´s a loop, it does 50+ times the exact same thing with the same SMTP username and password, the same receiver, the same content and most times I receive 50+ mails, all correct, so my code is definately fine, the SMTP server is fine, I´m not exceeding any limits or anything.
Anyway, here it is:

$path = $_SERVER["DOCUMENT_ROOT"]."phpmailer/";
set_include_path(get_include_path() . PATH_SEPARATOR . $path);

for($i = 0; $i < 60; $i++)
{
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "..."; // SMTP address
$mail->SMTPAuth = true;
$mail->Username = "..."; // my SMTP username
$mail->Password = "..."; // my SMTP password
$mail->From = "..."; // my mail address
$mail->FromName = "..."; // my name
$mail->AddAddress("..."); // my mail address
$mail->AddReplyTo("...", "..."); // my mail address and name
$mail->CharSet="utf-8"; 
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "Some Title";
$mail->Body    = "Some<br>HTML<br>text";
$mail->AltBody = "Some normal text";
$mail->Send();
}

Once in a while something goes wrong and I get

Warning: fputs() expects parameter 1 to be resource, integer given in

... /PHPMailer/class.smtp.php on line 215

I´ve checked, parameter 1 is the SMTP password.

If neccessary I can add, I have the latest version of PHPMailer, my Provider has PHP5.
But even if the version was not the latest, if 9 out of 10 times all goes fine and the 10th time still 35 or so emails go through without problems, why would then suddenly the password not be correct upon the 36th and again be correct upon the 37th?

Your code is connecting every run of the loop. This may cause connection issues, as you are not explicitly closing/clearing your object. Best way to do this is something like this:

// Settings that do not change before the loop
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "..."; // SMTP address
$mail->SMTPAuth = true;
$mail->Username = "..."; // my SMTP username
$mail->Password = "..."; // my SMTP password
$mail->From = "..."; // my mail address
$mail->FromName = "..."; // my name
$mail->AddReplyTo("...", "..."); // my mail address and name
$mail->CharSet="utf-8"; 
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "Some Title";
$mail->Body    = "Some<br>HTML<br>text";
$mail->AltBody = "Some normal text";

for($i = 0; $i < 60; $i++) {
  $mail->ClearAddresses();
  $mail->AddAddress("...");
  $mail->Send();
}

Thanks, I´ll try that.

how to send mails individually instead of sending to all recipients?
my code is:

function SendMail($msg,$subject,$addresses)
    {
    require "class.phpmailer.php";
    //Fetch from email here
    foreach($addresses as $key=>$val){
             $email = test_input($val);
            if((trim($email)=='') || (!filter_var($email, FILTER_VALIDATE_EMAIL))){
                unset($addresses[$key]);
            }
        }
        $addresses=array_unique($addresses);
    $row = FetchAllsettingsCustomMailchmp();
    //end fetch
    $mail = new PHPMailer();
    $mail->PluginDir = "";
    $mail->Host = "localhost";
    $mail->From = $row['email_from'];
    $mail->FromName = $row['sitename'];
    $mail->Subject =  $subject;
    foreach ($addresses as $address)
        $mail->AddAddress($address);
    $mail->MsgHTML($msg);
    $mail->IsHTML(true);
    $mail->AltBody ="Order";
    $mail->CharSet = 'UTF-8';
    $success = $mail->Send();
    $try = 1;

    while((!$success)&&($try<1)&&($mail->ErrorInfo!="SMTP Error: Data not accepted"))
        {
        sleep(5);
        $success = $mail->Send();
        $try++;
        }

    $mail->ClearAddresses();
    if(!$success)
        return false;
        else
        return true;
    }

function test_input($data) {
   $data = trim($data);
   $data = stripslashes($data);
   $data = htmlspecialchars($data);
   return $data;
}

@davidbcn

Hi, open your own thread to get responses.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.