【发布时间】:2021-06-09 14:08:29
【问题描述】:
亲爱的 Goblin Slayers(开发人员),我已经尝试解决这个问题两天了。我正在尝试为基于 PHP 邮件程序的公司构建一个用于营销目的的邮件程序,当我们发送 HTML 时,我的代码运行良好将文件发送给 6-8 个(或多或少)个收件人,但是当我们尝试通过我的 localhost 将 HTML 文件发送给超过 100 个收件人时,我收到以下错误:
2021-03-12 14:10:30 SMTP INBOUND: "452 4.5.3 Error: too many recipients"
2021-03-12 14:10:30 SERVER -> CLIENT: 452 4.5.3 Error: too many recipients
我的代码如下:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require_once 'folder/dbh.inc.php';
include 'folder/index.inc.php';
$content = file_get_contents('body_file.html');
// An array that contains the List of recipients
$emailst = array("100-500 recipients");
$emailst_length = count($emailst) - 1;
//Load Composer's autoloader
require 'vendor/autoload.php';
//Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
require 'folder/credentials.inc.php';
//Recipients
$mail->setFrom('emailOfTheCompany.com', 'company name');
$mail->addAddress('another email of the company', 'company name');
for ($i=0; $i <= $emailst_length; $i++) {
$mail->addBCC($emailst[$i]);
}
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->CharSet = 'utf-8';
$mail->Subject = 'Welcome To Subject';
$mail->Body = $content;
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>
【问题讨论】:
标签: php email client-server phpmailer contact-form