无法使用SwiftMailer发送电子邮件

时间:2012-05-30 11:09:08

标签: php ubuntu swiftmailer

我正在尝试使用SwiftMailer发送带有以下php代码的电子邮件。

$transport = Swift_SmtpTransport::newInstance('smtp.domain.com', 25);
$transport->setUsername(getenv('USER_NAME'));
$transport->setPassword(getenv('PASSWORD'));
$swift = Swift_Mailer::newInstance($transport);

$mail = Swift_Message::newInstance();
$mail->setSubject('Hello');
$mail->setFrom(array('sender@domain.com' => 'Sender Name' ));
$mail->setTo(array('receiver@domain.com' => 'Receiver Name'));
$mail->setBody('some message');

$result = $swift->send($mail, $failures);

if ($result)
{
    echo "Message successfully sent!";
}
else
{
    echo "There was an error:\n";
    print_r($failures);
}

以下错误即将来临......

  

出现错误:

     

数组([0] => receiver@domain.com)

我使用Mandrill作为SMTP ...

2 个答案:

答案 0 :(得分:2)

请务必使用真实的电子邮件地址,而不是receiver@domain.com和sender@domain.com。

另一件事 - 您可能需要设置SMTP服务器,用户名和密码才能从服务器发送电子邮件。

答案 1 :(得分:0)

如果变量名称尚不存在,它将被初始化为空数组,然后将失败添加到该数组中。如果变量已经存在,它将被类型转换为数组,并且将向其添加失败。