title: PHPMailer does not work with gmail
body: <p>after trying to let my PHPMailer run with gmail for some days I have to find some help here. I read nearly everything I could find here or in Google but none of the ideas helped until now. 
  I am using 
  * Windows 7 Home Basic 
  * Wampserver 2.2 with PHP vers. PHP Version 5.4.3
    all necessary extensions are set up like e. g. php_opensll
  * PHPMailer 5.2.9</p>
  
  <p>This is the script I am using:</p>
  
  <pre><code>&lt;?php
  //require 'PHPMailerAutoload.php';                                              // &lt;&lt;== I have tried this also - no sucess
  
  require 'class-phpmailer.php';
  require "class-smtp.php"; //"PHPMailerAutoload.php";
  // $mail-&gt;PluginDir //WB, 30 Nov 2014:omited if all files from phpmailer are in the same folder
  $mail = new PHPMailer();
  $mail-&gt;IsSMTP();
  $mail-&gt;Host = "smtp.gmail.com";
  $mail-&gt;Mailer = 'smtp';
  $mail-&gt;SMTPAuth = true;
  // I have tried both - TLS and SSL - with the required ports ==&gt;&gt; both are not working 
  $mail-&gt;Port = 465;
  $mail-&gt;SMTPSecure = 'ssl';
  // or try these settings (worked on XAMPP and WAMP):
  //$mail-&gt;Port = 587;
  //$mail-&gt;SMTPSecure = 'tls';
  
  $mail-&gt;Username = "wie****@gmail.com";      //my password ==&gt;&gt; works if I make a login oline to my account
  $mail-&gt;Password = "*************";  //my password ==&gt;&gt; works if I make a login oline to my account
  
  $mail-&gt;SMTPDebug  = 2;                      // &lt;&lt;== enables SMTP debug information (for testing)
  
  $mail-&gt;IsHTML(true);    // if you are going to send HTML formatted emails
  $mail-&gt;SingleTo = true; // if you want to send a same email to multiple users. multiple emails will be sent one-by-one.
  
  $mail-&gt;From = "wie****@gmail.com";                  //my gmail mail account
  $mail-&gt;FromName = "My Name";
  
  $mail-&gt;addAddress("art******@yahoo.com","art******"); //my yahoo mail account
  //$mail-&gt;addAddress("user.2@gmail.com","User 2");
  
  //$mail-&gt;addCC("user.3@ymail.com","User 3");
  //$mail-&gt;addBCC("user.4@in.com","User 4");
  
  $mail-&gt;Subject = "Testing PHPMailer with localhost";
  $mail-&gt;Body = "Hi,&lt;br /&gt;&lt;br /&gt;This system is working perfectly.";
  
  if(!$mail-&gt;Send())
      echo "Message was not sent &lt;br /&gt;PHPMailer Error: " . $mail-&gt;ErrorInfo;
  else
      echo "Message has been sent";
  ?&gt;
  </code></pre>
  
  <p>I am trying already any variation I could found in the net but nothing works. </p>
  
  <p>I have tried it with
  - 'PHPMailerAutoload.php' and 'class.phpmailer.php' as required class
  - “$mail->SMTPSecure = 'ssl';” and “$mail->Port = 465;”
   as well as with 
  - “$mail->SMTPSecure = 'tls';” and “$mail->Port = 587;”</p>
  
  <p>Here are the debugging log-files: </p>
  
  <blockquote>
    <p>Debug-Log when using TLS with port 587</p>
    
    <p>SMTP -> FROM SERVER:220 mx.google.com ESMTP cq6sm24503844pad.30 -
    gsmtp SMTP -> FROM SERVER: 250-mx.google.com at your service,
    [121.54.112.183] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS
    250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 SMTP
    -> FROM SERVER:220 2.0.0 Ready to start TLS SMTP -> FROM SERVER: 250-mx.google.com at your service, [121.54.112.183] 250-SIZE 35882577
    250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN
    OAUTHBEARER 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250
    SMTPUTF8 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
    <a href="https://support.google.com/mail/bin/answer.py?answer=78754" rel="nofollow">https://support.google.com/mail/bin/answer.py?answer=78754</a>
    cq6sm24503844pad.30 - gsmtp SMTP -> FROM SERVER:250 2.1.5 Flushed
    cq6sm24503844pad.30 - gsmtp SMTP -> FROM SERVER:530-5.5.1
    Authentication Required. Learn more at 530 5.5.1
    <a href="http://support.google.com/mail/bin/answer.py?answer=14257" rel="nofollow">http://support.google.com/mail/bin/answer.py?answer=14257</a>
    cq6sm24503844pad.30 - gsmtp SMTP -> ERROR: MAIL not accepted from
    server: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1
    <a href="http://support.google.com/mail/bin/answer.py?answer=14257" rel="nofollow">http://support.google.com/mail/bin/answer.py?answer=14257</a>
    cq6sm24503844pad.30 - gsmtp The following From address failed:
    wiedeia@gmail.com : MAIL not accepted from server,530,5.5.1
    Authentication Required. Learn more at 530 5.5.1
    <a href="http://support.google.com/mail/bin/answer.py?answer=14257" rel="nofollow">http://support.google.com/mail/bin/answer.py?answer=14257</a>
    cq6sm24503844pad.30 - gsmtp</p>
    
    <p>SMTP server error: 5.5.1 Authentication Required. Learn more at 530
    5.5.1 <a href="http://support.google.com/mail/bin/answer.py?answer=14257" rel="nofollow">http://support.google.com/mail/bin/answer.py?answer=14257</a> cq6sm24503844pad.30 - gsmtp Message was not sent PHPMailer Error: The
    following From address failed: wiedeia@gmail.com : MAIL not accepted
    from server,530,5.5.1 Authentication Required. Learn more at 530 5.5.1
    <a href="http://support.google.com/mail/bin/answer.py?answer=14257" rel="nofollow">http://support.google.com/mail/bin/answer.py?answer=14257</a>
    cq6sm24503844pad.30 - gsmtp</p>
    
    <p>SMTP server error: 5.5.1 Authentication Required. Learn more at 530
    5.5.1 <a href="http://support.google.com/mail/bin/answer.py?answer=14257" rel="nofollow">http://support.google.com/mail/bin/answer.py?answer=14257</a> cq6sm24503844pad.30 - gsmtp</p>
    
    <p>SMTP server error: 5.5.1 Authentication Required. Learn more at 530
    5.5.1 <a href="http://support.google.com/mail/bin/answer.py?answer=14257" rel="nofollow">http://support.google.com/mail/bin/answer.py?answer=14257</a> cq6sm24503844pad.30 - gsmtp</p>
    
    <p>Debug-Log when using SSL with port 465</p>
    
    <p>SMTP -> FROM SERVER:220 mx.google.com ESMTP kj9sm24304154pbc.37 -
    gsmtp SMTP -> FROM SERVER: 250-mx.google.com at your service,
    [121.54.112.183] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN
    XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER 250-ENHANCEDSTATUSCODES
    250-PIPELINING 250-CHUNKING 250 SMTPUTF8 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
    <a href="https://support.google.com/mail/bin/answer.py?answer=78754" rel="nofollow">https://support.google.com/mail/bin/answer.py?answer=78754</a>
    kj9sm24304154pbc.37 - gsmtp SMTP -> FROM SERVER:250 2.1.5 Flushed
    kj9sm24304154pbc.37 - gsmtp SMTP -> FROM SERVER:530-5.5.1
    Authentication Required. Learn more at 530 5.5.1
    <a href="http://support.google.com/mail/bin/answer.py?answer=14257" rel="nofollow">http://support.google.com/mail/bin/answer.py?answer=14257</a>
    kj9sm24304154pbc.37 - gsmtp SMTP -> ERROR: MAIL not accepted from
    server: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1
    <a href="http://support.google.com/mail/bin/answer.py?answer=14257" rel="nofollow">http://support.google.com/mail/bin/answer.py?answer=14257</a>
    kj9sm24304154pbc.37 - gsmtp The following From address failed:
    wiedeia@gmail.com : MAIL not accepted from server,530,5.5.1
    Authentication Required. Learn more at 530 5.5.1
    <a href="http://support.google.com/mail/bin/answer.py?answer=14257" rel="nofollow">http://support.google.com/mail/bin/answer.py?answer=14257</a>
    kj9sm24304154pbc.37 - gsmtp</p>
    
    <p>SMTP server error: 5.5.1 Authentication Required. Learn more at 530
    5.5.1 <a href="http://support.google.com/mail/bin/answer.py?answer=14257" rel="nofollow">http://support.google.com/mail/bin/answer.py?answer=14257</a> kj9sm24304154pbc.37 - gsmtp Message was not sent PHPMailer Error: The
    following From address failed: wiedeia@gmail.com : MAIL not accepted
    from server,530,5.5.1 Authentication Required. Learn more at 530 5.5.1
    <a href="http://support.google.com/mail/bin/answer.py?answer=14257" rel="nofollow">http://support.google.com/mail/bin/answer.py?answer=14257</a>
    kj9sm24304154pbc.37 - gsmtp</p>
    
    <p>SMTP server error: 5.5.1 Authentication Required. Learn more at 530
    5.5.1 <a href="http://support.google.com/mail/bin/answer.py?answer=14257" rel="nofollow">http://support.google.com/mail/bin/answer.py?answer=14257</a> kj9sm24304154pbc.37 - gsmtp</p>
    
    <p>SMTP server error: 5.5.1 Authentication Required. Learn more at 530
    5.5.1 <a href="http://support.google.com/mail/bin/answer.py?answer=14257" rel="nofollow">http://support.google.com/mail/bin/answer.py?answer=14257</a> kj9sm24304154pbc.37 - gsmtp</p>
  </blockquote>
  
  <p>I checked the links gmail is offering with the debugging. But nothing works. When I log into my account on the web with the same information for user and password it works. </p>
  
  <p>I also followed the advices I found in the net to allow less secure apps. Also I allowed the access to my account with Google using the link <a href="https://accounts.google.com/DisplayUnlockCaptcha" rel="nofollow">https://accounts.google.com/DisplayUnlockCaptcha</a></p>
  
  <p>Then I checked the ports with a port scanner both ports are mentioned as closed. But I guess they will be opened when requested by an application. A check with telnet smtp.gmail.com has been successful.  </p>
  
  <p>I tried the script also without running any antivirus and firewall – no result.  </p>
  
  <p>Slowly slowly I run a little bit mad with this issue. May be someone can help me here.</p>
  
  <p>Andreas</p>