简体   繁体   English

使用PHPMailer时看不到邮件日志,但是如果我使用简单的php mail()函数,我可以看到日志

[英]Can't see mail log when using PHPMailer but if I use simple php mail() function i can see log

php.ini php.ini

mail.log = "c:/wamp/logs/maillog.log"

PHPMailer_Email.php (Using below script, it doesn't write log in specified file but send email.) PHPMailer_Email.php (使用以下脚本,它不会在指定文件中写入日志,但会发送电子邮件。)

include 'vendor/autoload.php';
  $mail = new PHPMailer;
  $mail->isSMTP();
  $mail->SMTPDebug = 2;
  $mail->Host = "domain.example.net";
  $mail->Port = 25;
  $mail->From = $from;
  $mail->FromName = "From Name";
  $mail->addAddress($to);
  $mail->addReplyTo($from, "Reply");
  $mail->isHTML(true);
  $mail->Subject = $subject;
  $mail->Body = $body;
  $mail->AltBody = $body;
  if(!$mail->send()){
    echo "Mailer Error: ". $mail->ErrorInfo; die();
  }
  else{
    echo "Message has been sent successfully";
  }

Email.php (Using below script, it write log and also send email) Email.php (使用以下脚本,它可以写日志并发送电子邮件)

mail($to, $subject, $body);

Could anyone suggest how I can enable PHPMailer to write mail log in maillog.log file? 谁能建议我如何启用PHPMailer在maillog.log文件中写入邮件日志?

Your local log file is for your local mail server, but you're sending directly to an external server, so it's not going through your local server, so there's nothing to log. 您的本地日志文件用于您的本地邮件服务器,但是您直接发送到外部服务器,因此它不会通过本地服务器,因此没有什么可记录的。 If you want to capture debug output and log it, look at the options provided with the Debugoutput property - you can inject a callable and make it save wherever you like, like this: 如果要捕获调试输出并将其记录,请查看Debugoutput属性提供的选项-您可以注入一个callable并将其保存在任意位置,如下所示:

$mail->DebugOutput = function ($str, $level) {
  file_put_contents(
    '/path/to/log/file',
    date('Y-m-d H:i:s') . "\t" . $str,
    FILE_APPEND | LOCK_EX
  );
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM