使用 PHP 从数据库发送多封电子邮件
我需要帮助使用 PHP 从数据库发送多封电子邮件。我有一个有效的代码,但它只能允许其中一封电子邮件。有什么方法可以修改它以帮助我发送多个吗?
<?
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
//Gmail configuration
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the server
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "******@gmail.com"; // GMAIL username
$mail->Password = "785123nick"; // GMAIL password
$prize = "lol";
//End Gmail
$mail->From = "[email protected]";
$mail->FromName = "Jetstar";
$mail->Subject = "Order Redemption";
$mail->MsgHTML("You have bought " . $prize . " Print this and collect it at our office.");
//$mail->AddReplyTo("[email protected]","reply name"); //They answer here, optional
$mail->AddAddress("your-email","name to");
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) { //To see if we return a message or a value bolean
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
echo "Message sent!";
?>
I need help in sending multiple emails from database using PHP. I have a code that work, but it can only allow one email in it. Is there some way to modify it to help me send multiple ones?
<?
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
//Gmail configuration
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the server
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "******@gmail.com"; // GMAIL username
$mail->Password = "785123nick"; // GMAIL password
$prize = "lol";
//End Gmail
$mail->From = "[email protected]";
$mail->FromName = "Jetstar";
$mail->Subject = "Order Redemption";
$mail->MsgHTML("You have bought " . $prize . " Print this and collect it at our office.");
//$mail->AddReplyTo("[email protected]","reply name"); //They answer here, optional
$mail->AddAddress("your-email","name to");
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) { //To see if we return a message or a value bolean
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
echo "Message sent!";
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您想向多个收件人发送相同的电子邮件,并且您的电子邮件地址存储在数据库中,您可以执行以下操作:
$mail->AddAddress();
这样您就可以将多个电子邮件地址添加到您的邮件对象中,然后发送给所有人。
希望有帮助!
Assuming that you would like to send same email to multiple recipients and that your email addresses are stored in a database, you may do something like this:
$mail->AddAddress();
This way you can add multiple email addresses to your mail object and then send to all.
Hope it helps!
使用 phpmailer,您可以 只需调用
添加多个收件人addAddress
多次...显然,正如之前所建议的,您可能希望通过 cronjob,从而尊重邮件服务器施加的限制。
Using phpmailer, you may add multiple recipients simply calling
addAddress
multiple times...Obviously, as suggested before, you may want to call this script by mean of a cronjob, thus respecting limits imposed by the mail server.