简体   繁体   English

无法使用SwiftMailer发送电子邮件

[英]Cannot send email using SwiftMailer

I am trying to send email, with the following php code, using 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);
}

the following error is coming ... 以下错误即将来临......

There was an error: 有一个错误:

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

I am using Mandrill as SMTP ... 我使用Mandrill作为SMTP ...

Make sure you use real email addresses instead of receiver@domain.com and sender@domain.com. 确保使用真实的电子邮件地址而不是receiver@domain.com和sender@domain.com。

Another thing - you may need to set SMTP server, username and password in order to send emails from your server. 另一件事 - 您可能需要设置SMTP服务器,用户名和密码才能从您的服务器发送电子邮件。

If the variable name does not yet exist, it will be initialized as an empty array and then failures will be added to that array. 如果变量名称尚不存在,则将其初始化为空数组,然后将失败添加到该数组中。 If the variable already exists it will be type-cast to an array and failures will be added to it. 如果变量已经存在,它将被类型转换为数组,并且将向其添加失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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