Configure SwiftMailer To Use Yahoo! Mail

in #php3 years ago

My ISP has been blocking SMTP (port 25 and 456), making it difficult for me to test email notifications in application, especially when you use Sendmail for sending emails. So I reconfigured my application to use my Yahoo mail account, and it is not as straight forward as I think...

Enable Less Secured App Access

By default, Yahoo does not allow 3rd party client access. Head over to https://login.yahoo.com/myaccount/security/?.scrumb=lKUdk7JUldB and generate an application password. This password allows your application to access Yahoo SMTP server.

Configure SwiftMailer

$transport = (new Swift_SmtpTransport('smtp.mail.yahoo.com', 587, 'tls'))
    ->setUsername('[email protected]')
    ->setPassword('application-password');

$mailer = new Swift_Mailer($transport);

$message = (new Swift_Message('Test from ' . gethostname() . ' at ' . date('r')))
    ->setFrom(['[email protected]' => 'Hong'])
    ->setTo(['[email protected]'])
    ->setBody('Testing Yahoo SMTP server');

$result = $mailer->send($message);  

IMPORTANT NOTE

  • Use port 587 to avoid blocking by ISP
  • Always use TLS encryption with port 587
  • The username and FROM header MUST be your Yahoo email address.
  • Use the generated application password, instead of your mail account password.

Google SMTP

Configuration for Google is also similar. You must first enable less secure app access. Then generate password for your application.

Similarly, use TLS encryption with port 587. Username must be your GMail address.

Sort:  
Loading...

Coin Marketplace

STEEM 0.23
TRX 0.12
JST 0.029
BTC 67195.72
ETH 3491.41
USDT 1.00
SBD 3.14