-2
$mail = new YiiMailer();
$mail->setView('contact');
$mail->setData(array('register' => $model,'user' =>$user));
//$mail->clearLayout();//if layout is already set in config
$mail->setFrom('xxxx@gmail.com', 'amatra');
$mail->setTo($model->client_email);
$mail->setSubject('Amatra Registration');
$mail->setBody('Thank u for registering, to get server licence activation key ');
$mail->setSmtp('smtp.gmail.com', 465, 'ssl', true, 'xxxx@gmail.com', 'aconxontheroad');

var_dump($mail->send());
if($mail->send()) {
    return true;    
} else {
    return false;
}

I changed port and SMTPSecure but still outputs bool (false),I can't deduce where the error is.

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
  • In order to see errors, you need to do some actual error checking, and make use of PHPMailer’s debugging features, which you will find in the docs and examples. This code attempts to send your message twice, once for each time you call `send`. – Synchro Oct 08 '18 at 05:41
  • CLIENT -> SERVER: EHLO localhost 2018-10-08 00:23:20 CLIENT -> SERVER: AUTH LOGIN 2018-10-08 00:23:20 CLIENT -> SERVER: bGFzdGthZ2FtaTYyQGdtYWlsLmNvbQ== 2018-10-08 00:23:20 CLIENT -> SERVER: a2FnYW1p 2018-10-08 00:23:21 SMTP ERROR: Password command failed: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 support.google.com/mail/?p=BadCredentials t15-v6sm41674857pfj.7 - gsmtp 2018-10-08 00:23:21 CLIENT -> SERVER: QUIT SMTP Connect() failed – AbdulMUTIMF Oct 08 '18 at 07:31
  • So read the page that links to, and [read the PHPMailer docs that tell you what to do about it](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#read-the-smtp-transcript). You set `SMTPDebug = 1`, so you can't see all that the server is saying; set it to `2`. It also looks like you're using a very old version of PHPMailer, so you should update. – Synchro Oct 08 '18 at 07:34
  • i changed SMTPDebug=2 – AbdulMUTIMF Oct 08 '18 at 07:51
  • 2018-10-08 00:49:15 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP z22-v6sm16576242pgk.21 - gsmtp 2018-10-08 00:49:15 – AbdulMUTIMF Oct 08 '18 at 07:53
  • i find it,,if update is wil be solved? – AbdulMUTIMF Oct 08 '18 at 07:54

2 Answers2

1
$mail->SMTPDebug = 1; //optional

You can refer this post to clearly: Yii, Yiimailer doesn't send the mail (no error shown)

devil8910
  • 48
  • 9
  • Set this to 2, not 1. Also this should be a comment as it’s not an answer. – Synchro Oct 08 '18 at 05:37
  • it's runing for chaking error the erros is 2018-10-08 00:23:20 CLIENT -> SERVER: EHLO localhost 2018-10-08 00:23:20 CLIENT -> SERVER: AUTH LOGIN 2018-10-08 00:23:20 CLIENT -> SERVER: bGFzdGthZ2FtaTYyQGdtYWlsLmNvbQ== 2018-10-08 00:23:20 CLIENT -> SERVER: a2FnYW1p 2018-10-08 00:23:21 SMTP ERROR: Password command failed: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials t15-v6sm41674857pfj.7 - gsmtp 2018-10-08 00:23:21 CLIENT -> SERVER: QUIT SMTP Connect() failed. – AbdulMUTIMF Oct 08 '18 at 07:24
  • username and password was true,,and i setting gmails to less secure but still error – AbdulMUTIMF Oct 08 '18 at 07:25
0

Try the Yii2 Swift mailer.

Yii::$app->mailer->compose('contact/html')
 ->setFrom('from@domain.com')
 ->setTo($form->email)
 ->setSubject($form->subject)
 ->send();

https://www.yiiframework.com/extension/yiisoft/yii2-swiftmailer

Bira
  • 4,531
  • 2
  • 27
  • 42