title: How can I send mail with PHPMailer without enabling 'less secure app' access in Yahoo?
body: <p>I'm trying to make a PHP contact form and send the messages to several addresses.
  I'm sending it from the default address, my own, which is a Yahoo address, and it's SMTP server, with <a href="https://github.com/PHPMailer/PHPMailer" rel="nofollow noreferrer">PHPMailer</a>.</p>
  
  <p>I'm using a host with PHP 5.6. I've used the most update settings in a sample script:</p>
  
  <pre><code>session_start();
  date_default_timezone_set('Etc/UTC');
  require_once('../phpmailer/PHPMailerAutoload.php');
  
  echo '&lt;pre&gt;';
  $mail = new PHPMailer;
  $mail-&gt;CharSet = 'UTF-8';
  $mail-&gt;SMTPDebug = 3;
  $mail-&gt;isSMTP();
  $mail-&gt;Host = 'smtp.mail.yahoo.com';
  $mail-&gt;SMTPSecure = 'tls';
  $mail-&gt;Port = 587;
  $mail-&gt;SMTPAuth = true;
  $mail-&gt;Username = 'my_mail@yahoo.com';
  $mail-&gt;Password = 'my_password';
  
  $mail-&gt;setFrom('my_mail@yahoo.com', 'From Íñtërnâtiônàl form');
  $mail-&gt;addAddress('target@gmail.com', 'ラーメン丸 (ramen-maru)');
  $mail-&gt;isHTML(true);    
  $mail-&gt;Subject = '山本's demo mail (yamamoto)';
  $mail-&gt;Body    = 'Delicious HTML message with extra umami &lt;em&gt;うま味&lt;/em&gt;';
  $mail-&gt;AltBody = 'Savoury plain text note with extra umami うま味, too.';
  
  if(!$mail-&gt;send()) {
      echo 'Message could not be sent.';
      echo 'Mailer Error: ' . $mail-&gt;ErrorInfo;
  } else {
      echo 'Message has been sent';
  }
  echo '&lt;/pre&gt;';
  die("ok\n");
  </code></pre>
  
  <p>It does output this:</p>
  
  <pre><code>2017-01-06 21:25:35 Connection: opening to smtp.mail.yahoo.com:587, timeout=300, options=array (
  )
  2017-01-06 21:25:35 Connection: opened 
  2017-01-06 21:25:35 SERVER -&gt; CLIENT: 220 smtp.mail.yahoo.com ESMTP ready 
  2017-01-06 21:25:35 CLIENT -&gt; SERVER: EHLO myhosting.com
  2017-01-06 21:25:35 SERVER -&gt; CLIENT: 250-smtp.mail.yahoo.com
                                        250-PIPELINING
                                        250-SIZE 41697280
                                        250-8 BITMIME
                                        250 STARTTLS
  2017-01-06 21:25:35 CLIENT -&gt; SERVER: STARTTLS
  2017-01-06 21:25:35 SERVER -&gt; CLIENT: 220 2.0.0 Start TLS 
  2017-01-06 21:25:36 CLIENT -&gt; SERVER: EHLO myhosting.com
  2017-01-06 21:25:36 SERVER -&gt; CLIENT: 250-smtp.mail.yahoo.com
                                        250-PIPELINING
                                        250-SIZE 41697280
                                        250-8 BITMIME
                                        250 AUTH PLAIN LOGIN XOAUTH2 XYMCOOKIE
  2017-01-06 21:25:36 SMTP Error: Could not authenticate.
  2017-01-06 21:25:36 CLIENT -&gt; SERVER: QUIT
  2017-01-06 21:25:36 SERVER -&gt; CLIENT: 221 2.0.0 Bye
  2017-01-06 21:25:36 Connection: closed
  2017-01-06 21:25:36 SMTP connect() failed.
  
  Message could not be sent. Mailer Error: SMTP connect() failed.
  https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
  </code></pre>
  
  <p>Obviously, it fails with an authentication error, despite being well authenticated, with a right username and password.</p>
  
  <p>If I enable the "less secure apps" in Yahoo Account Security, then it does work correctly, showing:</p>
  
  <pre><code>2017-01-06 21:44:22 Connection: opening to smtp.mail.yahoo.com:587, timeout=300, options=array ()
  2017-01-06 21:44:22 Connection: opened
  2017-01-06 21:44:22 SERVER -&gt; CLIENT: 220 smtp.mail.yahoo.com ESMTP ready
  2017-01-06 21:44:22 CLIENT -&gt; SERVER: EHLO myhosting.com
  2017-01-06 21:44:22 SERVER -&gt; CLIENT: 250-smtp.mail.yahoo.com
                                    250-PIPELINING
                                    250-SIZE 41697280
                                    250-8 BITMIME
                                    250 STARTTLS
  2017-01-06 21:44:22 CLIENT -&gt; SERVER: STARTTLS
  2017-01-06 21:44:22 SERVER -&gt; CLIENT: 220 2.0.0 Start TLS
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: EHLO myhosting.com
  2017-01-06 21:44:23 SERVER -&gt; CLIENT: 250-smtp.mail.yahoo.com
                                    250-PIPELINING
                                    250-SIZE 41697280
                                    250-8 BITMIME
                                    250 AUTH PLAIN LOGIN XOAUTH2 XYMCOOKIE
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: AUTH LOGIN
  2017-01-06 21:44:23 SERVER -&gt; CLIENT: 334 ************
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: ********************************
  2017-01-06 21:44:23 SERVER -&gt; CLIENT: 334 ************
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: ************
  2017-01-06 21:44:23 SERVER -&gt; CLIENT: 235 2.0.0 OK
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: MAIL FROM:
  2017-01-06 21:44:23 SERVER -&gt; CLIENT: 250 OK , completed
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: RCPT TO:
  2017-01-06 21:44:23 SERVER -&gt; CLIENT: 250 OK , completed
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: DATA
  2017-01-06 21:44:23 SERVER -&gt; CLIENT: 354 Start Mail. End with CRLF.CRLF
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: Date: Fri, 6 Jan 2017 21:44:22 +0000
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: To: =?UTF-8?B?44Op44O844Oh44Oz5Li4IChyYW1lbi1tYXJ1KQ==?= 
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: From: =?UTF-8?B?UGFyYSBJw7F0w6tybsOidGnDtG7DoGxpesOmdGnDuG4=?= 
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: Subject: =?UTF-8?Q?=E5=B1=B1=E6=9C=AC_(yamamoto)_presenta:_II?=
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: Message-ID: 
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: X-Mailer: PHPMailer 5.2.21 (https://github.com/PHPMailer/PHPMailer)
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: MIME-Version: 1.0
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: Content-Type: multipart/alternative;
  2017-01-06 21:44:23 CLIENT -&gt; SERVER:   boundary="b1_ebc9bc65ff4eee7ae217e5d602991794"
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: Content-Transfer-Encoding: 8bit
  2017-01-06 21:44:23 CLIENT -&gt; SERVER:
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: This is a multi-part message in MIME format.
  2017-01-06 21:44:23 CLIENT -&gt; SERVER:
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: --b1_ebc9bc65ff4eee7ae217e5d602991794
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: Content-Type: text/plain; charset=UTF-8
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: Content-Transfer-Encoding: 8bit
  2017-01-06 21:44:23 CLIENT -&gt; SERVER:
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: Mensaje de prueba 2 con extra de umami うま味
  2017-01-06 21:44:23 CLIENT -&gt; SERVER:
  2017-01-06 21:44:23 CLIENT -&gt; SERVER:
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: --b1_ebc9bc65ff4eee7ae217e5d602991794
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: Content-Type: text/html; charset=UTF-8
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: Content-Transfer-Encoding: 8bit
  2017-01-06 21:44:23 CLIENT -&gt; SERVER:
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: Mensaje de prueba 2 con extra de umami うま味
  2017-01-06 21:44:23 CLIENT -&gt; SERVER:
  2017-01-06 21:44:23 CLIENT -&gt; SERVER:
  2017-01-06 21:44:23 CLIENT -&gt; SERVER:
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: --b1_ebc9bc65ff4eee7ae217e5d602991794--
  2017-01-06 21:44:23 CLIENT -&gt; SERVER:
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: .
  2017-01-06 21:44:23 SERVER -&gt; CLIENT: 250 OK , completed
  2017-01-06 21:44:23 CLIENT -&gt; SERVER: QUIT
  2017-01-06 21:44:23 SERVER -&gt; CLIENT: 221 Service Closing transmission
  2017-01-06 21:44:23 Connection: closed
  Message has been sent
  </code></pre>
  
  <p>Well, what do I need to do to send mail without having to enable 'less secure apps'? </p>
  
  <p>In Gmail there are plenty of tutorials to do it with OAuth2 and creating an app key. Does it work in the same way for Yahoo? 
  If it is like that, what do I need to do to use PHPMailerOAuth? 
  Where do I apply for the key? And which key is it; Flurry, YQL, Gemini?</p>