Send email using Phpmailer with Yahoo/Gmail

I believe, Phpmailer class is most popular class throughout the web. You can easily integrate this class to your application to send email. If you want to send email using gmail smtp or yahoo business email smtp( yahoo free email doesn’t provide smtp, pop services) through this class, you may face some problems like me 😉


I’ve used this class to send email using yahoo business account and gmail account. To send email through yahoo smtp, First get the class files from http://phpmailer.worxware.com/, remember – you have to take correct version of php4 or php5. Then here is the sample code for your mail sending script with yahoo business smtp –

<?php
 
 require ("class.phpmailer.php");
 $mail = new PHPMailer();
 $mail->From     = "FROM EMAIL ADDRESS";
 $mail->FromName = "FROM NAME";
 
 $mail->IsSMTP(); 
 
 $mail->SMTPAuth = true;     // turn of SMTP authentication
 $mail->Username = "YAHOO BUSINESS ACCOUNT";  // SMTP username
 $mail->Password = "YAHOO BUSINESS ACCOUNT PASSWORD"; // SMTP password
 $mail->SMTPSecure = "ssl";
 $mail->Host = "smtp.bizmail.yahoo.com";
 $mail->Port = 465;
 
 $mail->SMTPDebug  = 2; // Enables SMTP debug information (for testing, remove this line on production mode)
 // 1 = errors and messages
 // 2 = messages only
  
 $mail->Sender   =  "EMAIL ADDRESS TO RECIEVE BOUNCES";// $bounce_email;
 $mail->ConfirmReadingTo  = "EMAIL ADDRESS TO GET READING REPORT";
 
 $mail->AddReplyTo("ADDRESS TO GET REPLY","NAME");
 $mail->IsHTML(true); //turn on to send html email
 $mail->Subject = "EMAIL SUBJECT";

 $mail->Body     =  "EMAIL MESSAGE";
 $mail->AltBody  =  "ALTERNATIVE MESSAGE FOR TEXT WEB BROWSER LIKE SQUIRRELMAIL";
 
 $mail->AddAddress("RECIPIENT ADDRESS","RICIPIENT NAME");
       
 if($mail->Send()){
  $mail->ClearAddresses();  
 }
 
?>  

That’s it. If you see the following errors on debug

SMTP -> ERROR: Failed to connect to server: Connection timed out (110) Sending failed ()!
SMTP -> ERROR: Failed to connect to server: Connection timed out (110) Failed to send notification to Admin.

you have to confirmed that port 465 is opened, contact your hosting to open this port.

Pretty simple. I believe similar settings will ok with Gmail.

Advertisements

9 thoughts on “Send email using Phpmailer with Yahoo/Gmail

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s