sending mail with gmail error: SMTP server did not accept password
Notice: This thread is very old.
- thcom
- Backer | 94
hi, i try to send email with smtpMailer with gmail
my config:
smtp.host = "smtp.gmail.com"
smtp.username = "MyAccountOnGMail@gmail.com"
smtp.password = "YesIHaveRihtPassword"
smtp.secure = "ssl"
code:
$mail = $this->mail($email, 'obnova hesla');
$body = "SOME BODY TEXT "
$mail->setBody($body);
$mail->send();
dump($mail) shows this
Nette\Mail\Mail(8) {
"mailer" private => Nette\Mail\SmtpMailer(7) {
"connection" private => NULL
"host" private => "smtp.gmail.com" (14)
"port" private => 465
"username" private => "CENSORED@gmail.com" (26)
"password" private => "CENSORED" (8)
"secure" private => "ssl" (3)
"timeout" private => 20
}
"attachments" private => array(0)
"inlines" private => array(0)
"html" private => NULL
"basePath" private => NULL
"headers" private => array(6) {
"MIME-Version" => "1.0" (3)
"X-Mailer" => "Nette Framework" (15)
"Date" => "Tue, 12 May 2015 07:55:27 +0200" (31)
"From" => array(1) {
"CENSORED" (16)
}
"To" => array(3) {
"CENSORED" => NULL
}
"Subject" => "obnova hesla" (12)
}
"parts" private => array(0)
"body" private => "CENSORED" (271)
}
nette version 2.0
can you please help me, what is wrong
i send max 10 – 30 mails per day, so i believe that is no problem with this limit
thank you
- iguana007
- Member | 970
But this will probably not work, if you are using 2-step verification – you should find out easily here: https://www.google.com/…sssecureapps
- tpr
- Member | 55
Here is a working snippet. Notice that I use $mailer->send while you use $mail->send.
It sends using gmail when in debug mode.
<?php
$mail = new Message;
$mail->setFrom('John <john@example.com>')
->addTo('johnny@gmail.com')
->setSubject('Hello there')
->setHtmlBody('Lorem ipsum...');
if (Nette\Configurator::detectDebugMode()) {
$mailer = new Nette\Mail\SmtpMailer(array(
'host' => 'smtp.gmail.com',
'username' => 'myname@gmail.com',
'password' => 'mypass',
'secure' => 'ssl',
));
} else {
$mailer = new SendmailMailer;
}
$mailer->send($mail);
?>