【问题标题】:send mails via swift mailer通过 swift mailer 发送邮件
【发布时间】:2012-01-24 15:40:14
【问题描述】:

我尝试通过 swiftmailer 发送邮件,我的代码是:

$message->setFrom($from);
$message->setBody($template, 'text/html');
$message->setTo($from);
$message->addPart($text, 'text/plain');
//$message->attach(Swift_Attachment::fromPath('D:/file.txt'));
// send message
if ($recipients = $swift->send($message, $failures)) { 

但问题是我收到一条空消息! $template 是一个包含 html 代码的变量!

【问题讨论】:

  • 您是否尝试打印出$template 以确保它不为空?
  • 耶!我在 setbody() 函数之前打印了它!没关系!

标签: php swiftmailer


【解决方案1】:

忘记 $failures 参数。只需使用 try catch !

try 
{
    //... all of your code
    $swift->send($message);
}
catch(Exception $exception)
{
    //A big object containing the error message
    print_r($exception);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-06
    • 1970-01-01
    • 2011-01-30
    • 2012-01-14
    • 2015-07-25
    • 2015-11-02
    • 2013-06-23
    相关资源
    最近更新 更多