Sending e-mails via SMTP does not work

Notice: This thread is very old.
radas
Member | 225
+
0
-

Tested with Nette 2.1-dev (2013–04–08) and 2.0.10.

$mailer = new SmtpMailer(array(
  'host' => 'smtp.gmail.com',
  'port' => 465,
  'username' => 'mail@gmail.com',
  'password' => 'password',
  'secure' => 'ssl'
));

$mail = new Message();

$mail->addTo('mail@gmail.com')
  ->setSubject('Test e-mail')
  ->setBody('This is an e-mail.');

try
{
  $mailer->send($mail);
}
catch (SmtpException $e)
{
  echo $e->getMessage();
}

The result is: “SMTP server did not accept RCPT TO:”.

The same problem is with smtp.seznam.cz, but with PHPMailer library v5.1 is all ok, e-mails can be sent via smtp.google.com and smtp.seznam.cz without problems.

radas
Member | 225
+
0
-

Ooops! I'm sorry. I forgot

$mail->setFrom(...);

I didn't know, when sending via SMTP, calling setFrom() is neccessary.