0

My email is working when i use my own email address but I need to run this using website's newly create email. This email is created using gmail.

Here's my code:

function phpMailer($emailTo, $subject, $body)
    {

        $email_temp = $body;
        $to = $emailTo;
        Yii::import('application.extensions.phpmailer.JPhpMailer');
        $mail = new JPhpMailer;
        $mail->IsSMTP();
        //$mail->Host = 'smtp.googlemail.com:465';
        $mail->Host = 'smtp.gmail.com';
        $mail->SMTPSecure = "tls";
        $mail->Port = 587;//465;
        $mail->SMTPAuth = true;
        $mail->SMTPDebug = true;
        $mail->Username = 'info@domainname.com';
        $mail->Password = 'xxxxxxxx';
        $mail->SetFrom('info@domainname.com', 'domainname'); //Send 'From' User
        $mail->Subject = $subject;
        $mail->AltBody = $email_temp;
        $mail->MsgHTML($email_temp); // message /template 
        $mail->AddAddress($to); //Send mail 'To' User 

        //check if mail sent successfully
        if($mail->Send())
            return true;

        return false;
    }

I am getting following response when debug using code 2.

SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "220 smtp.gmail.com ESMTP c3sm6277150qge.12 - gsmtp " 
SMTP -> get_lines(): $data is "220 smtp.gmail.com ESMTP c3sm6277150qge.12 - gsmtp " 
SMTP -> FROM SERVER:220 smtp.gmail.com ESMTP c3sm6277150qge.12 - gsmtp 
SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "250-smtp.gmail.com at your service, [54.209.41.153] " 
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] " 
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] " 
SMTP -> get_lines(): $str is "250-SIZE 35882577 " 
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 " 
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 " 
SMTP -> get_lines(): $str is "250-8BITMIME " 
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME " 
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME " 
SMTP -> get_lines(): $str is "250-STARTTLS " 
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS " 
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS " 
SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES " 
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES " 
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES " 
SMTP -> get_lines(): $str is "250-PIPELINING " 
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING " 
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING " 
SMTP -> get_lines(): $str is "250-CHUNKING " 
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING " 
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING " 
SMTP -> get_lines(): $str is "250 SMTPUTF8 " 
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 " 
SMTP -> FROM SERVER: 250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 
SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "220 2.0.0 Ready to start TLS " 
SMTP -> get_lines(): $data is "220 2.0.0 Ready to start TLS " 
SMTP -> FROM SERVER:220 2.0.0 Ready to start TLS 
SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "250-smtp.gmail.com at your service, [54.209.41.153] " 
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] " 
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] " 
SMTP -> get_lines(): $str is "250-SIZE 35882577 " 
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 " 
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 " 
SMTP -> get_lines(): $str is "250-8BITMIME " 
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME " 
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME " 
SMTP -> get_lines(): $str is "250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH " 
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH " 
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH " 
SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES " 
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES " 
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES " 
SMTP -> get_lines(): $str is "250-PIPELINING " 
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING " 
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING " 
SMTP -> get_lines(): $str is "250-CHUNKING " 
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING " 
SMTP -> get_lines(): $data was "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING " 
SMTP -> get_lines(): $str is "250 SMTPUTF8 " 
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 " 
SMTP -> FROM SERVER: 250-smtp.gmail.com at your service, [54.209.41.153] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 
SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "334 VXNlcm5hbWU6 " 
SMTP -> get_lines(): $data is "334 VXNlcm5hbWU6 " 
SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "334 UGFzc3dvcmQ6 " 
SMTP -> get_lines(): $data is "334 UGFzc3dvcmQ6 " 
SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "534-5.7.14 SMTP -> get_lines(): $data is "534-5.7.14 SMTP -> get_lines(): $data was "534-5.7.14 SMTP -> get_lines(): $str is "534-5.7.14 w1qusykfYpU2yVqlT4ZEIFrXPep3JwRh3FfzQc7ddey5QQmBd4JbZi9tNFSnBFHW7IdOcx " 
SMTP -> get_lines(): $data is "534-5.7.14 SMTP -> get_lines(): $data was "534-5.7.14 SMTP -> get_lines(): $str is "534-5.7.14 NbZA5LEBoeSZEcjcwhBW_Kfziy5pHrZal2opZ3uBdoF-WM4OPoMDnfG_w_7fNOtjA8HGPw " 
SMTP -> get_lines(): $data is "534-5.7.14 SMTP -> get_lines(): $data was "534-5.7.14 SMTP -> get_lines(): $str is "534-5.7.14 zL0OcSfQMG3sJ1fwVuYZTRL3prN6EZudpmCgygKIv1lqW9r7w8fXC5v-3qGXWP3PxghHp8 " 
SMTP -> get_lines(): $data is "534-5.7.14 SMTP -> get_lines(): $data was "534-5.7.14 SMTP -> get_lines(): $str is "534-5.7.14 fVgbNTqeHZhv728Su3O-QGwFNdsU> Please log in via your web browser and " 
SMTP -> get_lines(): $data is "534-5.7.14 Please log in via your web browser and " 
SMTP -> get_lines(): $data was "534-5.7.14 Please log in via your web browser and " 
SMTP -> get_lines(): $str is "534-5.7.14 then try again. " 
SMTP -> get_lines(): $data is "534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. " 
SMTP -> get_lines(): $data was "534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. " 
SMTP -> get_lines(): $str is "534-5.7.14 Learn more at " 
SMTP -> get_lines(): $data is "534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at " 
SMTP -> get_lines(): $data was "534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at " 
SMTP -> get_lines(): $str is "534 5.7.14 https://support.google.com/mail/answer/78754 c3sm6277150qge.12 - gsmtp " 
SMTP -> get_lines(): $data is "534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 c3sm6277150qge.12 - gsmtp " 
SMTP -> ERROR: Password not accepted from server: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 c3sm6277150qge.12 - gsmtp 
SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "250 2.1.5 Flushed c3sm6277150qge.12 - gsmtp " 
SMTP -> get_lines(): $data is "250 2.1.5 Flushed c3sm6277150qge.12 - gsmtp " 
SMTP -> FROM SERVER:250 2.1.5 Flushed c3sm6277150qge.12 - gsmtp 
SMTP Error: Could not authenticate.
Curious Developer
  • 705
  • 3
  • 9
  • 29
  • Please, just read your error message that tells you to go [here](https://support.google.com/mail/answer/78754). You're running an old version of [PHPMailer](https://github.com/PHPMailer/PHPMailer) and you've based your code on a long-obsolete example. There are hundreds of duplicates of this question, and it's covered extensively in [the docs](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting). Really, you're just not trying. – Synchro Dec 18 '15 at 08:07
  • @Synchro: Not really I was using my own gmail email until now and the mails was working fine. Today I implemented client's email which he bought for his website and mails stopped working. When I debug, i get the above messages. The problem wasn't in code at all. This happened due to google's more secured settings for emails. – Curious Developer Dec 18 '15 at 08:47

1 Answers1

0

I found the solution to this problem. You need to enforce access to less secure apps from link. less secure apps setting or if you have configured email from google mail apps then go to admin->security->basic setting and do the above.

Curious Developer
  • 705
  • 3
  • 9
  • 29