【发布时间】:2020-04-20 11:31:30
【问题描述】:
我在使用 PHPMailer 和 cron 作业自动发送电子邮件时遇到问题。我正在使用共享托管服务器和 CPanel。我已经测试了我的 PHPmailer 安装,并且能够通过在浏览器中运行以下脚本成功发送基本电子邮件。
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
/* Exception class. */
require '/home/eepherg/public_html/mobiq1.2/lib/PHPMailer-master/src/Exception.php';
/* The main PHPMailer class. */
require '/home/eepherg/public_html/mobiq1.2/lib/PHPMailer-master/src/PHPMailer.php';
/* SMTP class, needed if you want to use SMTP. */
require '/home/eepherg/public_html/mobiq1.2/lib/PHPMailer-master/src/SMTP.php';
/* Create a new PHPMailer object. Passing TRUE to the constructor enables exceptions. */
$mail = new PHPMailer(TRUE);
/* Set the mail sender. */
$mail->setFrom('darth@empire.com', 'Darth Vader');
/* Add a recipient. */
$mail->addAddress('test@provision.com', 'Emperor');
/* Set the subject. */
$mail->Subject = 'Force';
/* Set the mail message body. */
$mail->Body = 'There is a great disturbance in the Force.';
/* Finally send the mail. */
$mail->send();
?>
我已经按照以下设置了一个 CRON 作业,每天运行一次......
12 00 * * * /usr/local/bin/php /home/eepherg/public_html/mobiq1.2/test.php
此 CRON 作业运行时没有任何错误,但未收到电子邮件。我的参考文献是否存在问题,或者是否有人知道为什么脚本在浏览器中运行时可以工作,但在使用 CRON 作业运行时不能工作?
【问题讨论】:
标签: php email cron phpmailer cpanel