Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用数据库连接使用phpmailer发送邮件()的正确方法_Php_Mysql_Sendmail_Phpmailer_Mailing List - Fatal编程技术网

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

使用数据库连接使用phpmailer发送邮件()的正确方法,php,mysql,sendmail,phpmailer,mailing-list,Php,Mysql,Sendmail,Phpmailer,Mailing List,我正在尝试修改phpmailer db mailer以使用sendmail,下面的代码是否正确?。我正在尝试将其应用到一个网站中,以向大约2-300个联系人的客户群发送电子邮件。 谢谢:-) 这应该可以,但请确保托管公司支持此功能。您对此代码有实际问题吗?没有,我刚刚合并了使用邮件功能的simple mailer脚本和使用smtp功能的db mailer,删除了smtp部分,并从另一个脚本中添加了sendmail部分,我只是想确保我对代码的修改是正确的:-)。在脚本中,它说WHERE id=$

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



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

您对此代码有实际问题吗?没有,我刚刚合并了使用邮件功能的simple mailer脚本和使用smtp功能的db mailer,删除了smtp部分,并从另一个脚本中添加了sendmail部分,我只是想确保我对代码的修改是正确的:-)。在脚本中,它说WHERE id=$id,我是否必须定义$id,因为我在脚本或phpmailer.php中找不到对它的任何其他引用
<?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();
}
?>