Jump to content


This topic is now archived and is closed to further replies.


PHPMailer sending mail to Yahoo through Gmail SMTP

Recommended Posts


         I am using the latest version of PHPMailer to try and send mails. The SMTP server is configured to use the Gmail SMTP. Now the problem is that when I am sending mails to a person with a Gmail account there seems to be no problem but when I am sending my mail to someone with a non Gmail account for example Yahoo. The mail never reaches(I have checked the SPAM folder). My PHP Mailer setup is as follows-:

 // optional, gets called from within class.phpmailer.php if not already  loaded
 $mail = new PHPMailer();

$body = "<html><head></head><body><strong>This is a 
 System generated message. PLEASE DO NOT REPLY TO THIS  
MAIL.</strong><br />Click on the following link to activate  your 
account-:<br /><a  href='http://www.google.co.in'>Click  Here !! 
</a><br />END OF  MESSAGE.</body></html>"; 
$body = eregi_replace("[\]",'',$body);

 $mail->IsSMTP(); // telling the class to use  
SMTP$mail->Host       = "smtp.gmail.com"; // 
 SMTP server$mail->SMTPDebug  =  2;                     
 // enables SMTP debug information (for 
 // 1 = errors and 
 // 2 = messages only$mail->SMTPAuth =  true;                  
 // enable SMTP authentication
$mail->SMTPSecure = "tls";                 
 // sets the prefix to the  
servier$mail->Host  =  "smtp.gmail.com";      // sets GMAIL as the SMTP  
server$mail->Port  = 587;                   
 // set the SMTP port for the GMAIL server
$mail->Username   = "foobar@gmail.com";  // GMAIL username
$mail->Password   = "foobar";            // GMAIL password 
$mail->SetFrom("foobar@gmail.com", "foo"); 
 $mail->AddReplyTo("foobar@gmail.com", "foo"); 
 $mail->Subject    = "foo bar"; 
 $mail->AltBody    = "To view the message, please use an HTML 
 compatible email viewer!"; // optional, comment out and test 
 $mail->MsgHTML($body); $address = $_GET['email'];
if(!$mail->Send()) {  
 echo "Mailer Error: " . $mail->ErrorInfo;} 
else {  }    
<html><head><meta http-equiv="Content-Type" 
< body></body></html>

My Questions are as follows-:

  1. Do I have to reconfigure my SMTP every time I send my mail to a different account ? For example if I have to send it to a Yahoo account do I have to use the Yahoo SMTP or when I send my mail to a Rediff account do I have to use the Rediff SMTP ??PHPMailer doesn't report any errors, it just says that it sent the message but the message never arrives. Can't I just use one SMTP and send mails to any account ?
  2. I am using WAMP server on my PC to run my Apache Web Server. Will this create problems in sending mails even if PHPMailer is configured correctly ?
  3. Is it necessary to add a name with the receiver address in the line-:

    Do I have to write it like this


    $mail->AddAddress($address,"Receiver Name");

    Since my mail will be sent to anyone signing up specifying the correct receiver name every time will be a little difficult to do.

  4. I am getting an error on the line-:

    $body = eregi_replace("[\]",'',$body);

    The problem is that the function eregi_replace() has become deprecated. According to the php.net documentation I have to use preg_replace() with the " i " switch. But since I am beginner to PHP and regular expression I can't figure out how to do that. Can someone give the code which accomplishes the same task as the line above using preg_replace. 


    Thank You.




Share this post

Link to post
Share on other sites

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.