我正在使用modMail类发送自定义电子邮件。我已经遵循了MODX网站上的指南,并使用了以下代码,我将其放在一个代码段中:
$message = $modx->getChunk('myEmailTemplate');
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_BODY,$message);
$modx->mail->set(modMail::MAIL_FROM,'me@example.org');
$modx->mail->set(modMail::MAIL_FROM_NAME,'Johnny Tester');
$modx->mail->set(modMail::MAIL_SUBJECT,'Check out my new email template!');
$modx->mail->address('to','user@example.com');
$modx->mail->address('reply-to','me@xexample.org');
$modx->mail->setHTML(true);
if (!$modx->mail->send()) {
$modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$modx->mail->mailer->ErrorInfo);
}
$modx->mail->reset();
该片段已被修改为包含来自自定义块的消息,并且电子邮件地址已被替换为正确的消息。该片段发送了一次电子邮件,但再也没有。我不知道是什么原因导致这种行为阻止它发送电子邮件。
我已经读过使用重置功能$modx->mail->reset();
重置电子邮件字段并允许再次发送电子邮件但我觉得这会导致问题。
在[[!email]]
有没有人知道为什么电子邮件没有被发送,即使它只运行一次?
答案 0 :(得分:1)
如果块中存在错误或处理块,则modx永远不会到达记录错误的位置。尝试类似的事情:
if (!$modx->mail->send()) {
$modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$modx->mail->mailer->ErrorInfo);
}else{
$modx->log(modX::LOG_LEVEL_ERROR,'This mail was sent: '.$message);
}
看它是否记录了什么。但除此之外你有什么是完全正确的 - 尝试取出$ message变量并发送一个字符串。如果它发送一次邮件,那么其他东西一定是错的。我开始查看邮件服务器日志,标题,垃圾邮件[gmail ??]等等。