I'm using PHPMailer v6.1.5 here in May 2020, and I am on shared GoDaddy servers via cPanel. I have copied all the PHPMailer files into their own directory off of my root directory. I can send one email at a time just fine. But the moment I put in a loop, sending out 4 - 10 emails, it crashes (something about unexpected 'use'). It's my belief that I cannot use Composer in my case. Any thoughts on how I can get it to work in a loop? Apologies.. but there are lots of these questions in Stackoverflow going back years.. but none seem to work in my situation.
So here is my code ...........
$path = '/home/myrootdirectory/public_html/PHPMailer/';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
// load all the PHPMailer classes
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require $path . '/src/Exception.php';
require $path . '/src/PHPMailer.php';
require $path . '/src/SMTP.php';
$mail = new PHPMailer(true);
$mail->From = $fromEmail;
$mail->FromName = $fromFullName;
$mail->addAddress($toEmail, $toFullName);
$mail->addBCC("admin@mycompany.com");
if ($fromSenderCopyYN=="Y") {
$mail->addBCC($fromEmail);
}
// Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $msg;
$mail->AltBody = $txtmsg;
if(!$mail->send()) {
// OK
}else{
// Not OK
}
=================================
Any help would be very appreciated.