简体   繁体   中英

send mails via swift mailer

I try to send a mail via swiftmailer and my code is :

$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)) { 

but the problem is I recieve an empty message ! $template is a variable which contains html code !

Forget about $failures parameter. Just use a try catch !

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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