gpt4 book ai didi

php - 使用数据库连接通过 phpmailer 发送邮件()的正确方法

转载 作者:行者123 更新时间:2023-11-29 14:37:22 26 4
gpt4 key购买 nike

我正在尝试修改 phpmailer db 邮件程序以使用 sendmail,下面的代码是否正确?我正在尝试将其实现到一个网站中,向大约 2-300 名联系人的客户群发送电子邮件。谢谢:-)

<?php
require_once('./send/class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch

$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);


$mail->SetFrom('list@mydomain.com', 'List manager');
$mail->AddReplyTo('list@mydomain.com', 'List manager');

$mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication";

$query = "SELECT full_name, email, photo FROM employee WHERE id=$id";
$result = @MYSQL_QUERY($query);

while ($row = mysql_fetch_array ($result)) {
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAddress($row["email"], $row["full_name"]);
$mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");

if(!$mail->Send()) {
echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) . ') ' . $mail->ErrorInfo . '<br>';
} else {
echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "&#64;", $row["email"]) . ')<br>';
}
// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
$mail->ClearAttachments();
}
?>

最佳答案

这应该可行,但请确保托管公司支持此功能。

关于php - 使用数据库连接通过 phpmailer 发送邮件()的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8769946/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com