
[英]Zend Framework: Is there a way to get the path to the view template directory?
[英]Is there a way to unset or delete msgHTML/view template in phpmailer
我有一个带有 email 表单响应的网站。 单击时我需要发送 2 封电子邮件,并且正在使用超薄框架、msgHTML 和 twig。 我通过条件设置 twig 模板,以显示该模板的一部分为第一个 email 和另一部分。 不工作,因为第一个 email 正文消息已添加到第二个。
所以我创建了 2 个 phpmailer 实例来发送 2 个单独的 twig 模板,但出现了同样的错误,它在最后一个 email 正文消息中添加了 2 个模板。
有没有办法取消设置 msgHTML 消息或视图?
$mailu = new PHPMailer; $maila = new PHPMailer;
$mailu->isHTML(true); $maila->isHTML(true);
$mailu->isSMTP(); $maila->isSMTP();
$mailu->Host = 'XXX'; $maila->Host = 'XXX';
$mailu->Port = 587; $maila->Port = 587;
$mailu->SMTPAuth = true; $maila->SMTPAuth = true;
$mailu->SMTPSecure = 'tls'; $maila->SMTPSecure = 'tls';
$mailu->Username = 'XXX; $maila->Username = 'XXX';
$mailu->Password = 'XXX'; $maila->Password = 'XXX';
$mailu->SMTPDebug = 0; $maila->SMTPDebug = 0;
$mailu->setLanguage('es'); $maila->setLanguage('es');
$mailu->CharSet="utf-8"; $maila->CharSet="utf-8";
$mailu->clearCustomHeaders(); $maila->clearCustomHeaders();
$mailu->Subject = $subject; $maila->Subject = $subject;
$marrayu = array('user'=>true, 'name'=>$name, 'email'=>$email, 'subject'=>$subject, 'message'=>$message, 'phone'=>$phone);
$mailu->msgHTML($this->view->render($response, 'templates/mailu.twig', array( "marray" => $marrayu )));
$mailu->setFrom($domainmail, 'NMV');
$mailu->addAddress($email, $name);
$mailu->addReplyTo($domainmail, 'NMV');
$mailu->send();
$marraya = array('user'=>false, 'name'=>$name, 'email'=>$email, 'subject'=>$subject, 'message'=>$message, 'phone'=>$phone);
$maila->msgHTML($this->view->render($response, 'templates/maila.twig', array( "marray" => $marraya )));
$maila->setFrom($email, $name);
$maila->addAddress($domainmail,'NMV');
$maila->send();
return $this->response->withStatus(200)->withHeader('Location', $anchor);
有什么建议么?
msgHTML
确实会覆盖Body
属性,并且新实例无法从另一个实例中保留正文,因此我会在上游进一步寻找原因。
但是,您可以像这样清除任何现有的主体:
$mail->Body = ‘’;
$mail->AltBody = ‘’;
我在这篇文章中找到了答案Slim framework and email template rendering issue with PHPmailer
正如我所料,一切都很好,但是视图假设要加入渲染,因此将其更改为 fetch 也可以解决问题,因为我得到了 HTTP/1.1 200 OK Content-Type: text/html; charset=UTF-8 header 在电子邮件的顶部。
谢谢您的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.