fayslr
fayslr

Reputation: 1

Cannot send email using SwiftMailer

I am trying to send email, with the following php code, using SwiftMailer.

$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('[email protected]' => 'Sender Name' ));
$mail->setTo(array('[email protected]' => '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] => [email protected] )

I am using Mandrill as SMTP ...

Upvotes: 0

Views: 894

Answers (2)

Sergey Kornilov
Sergey Kornilov

Reputation: 1792

Make sure you use real email addresses instead of [email protected] and [email protected].

Another thing - you may need to set SMTP server, username and password in order to send emails from your server.

Upvotes: 2

starjava
starjava

Reputation: 443

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.

Upvotes: 0

Related Questions