2
votes

i have a issue sending mail using smtp mail class when i use my send email code using smtp in my local system at that time is working prefect but when i try that code in live server i got every time smtp connect failed error

i use this code for send mail using smtp mailer class

require 'mail/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); 
$mail->SMTPDebug = 2; 
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;  
$mail->Username = '[email protected]'; 
$mail->Password = 'mypassword';        
$mail->SMTPSecure = 'tls';             
$mail->From = '[email protected]';
$mail->FromName = 'Mailer';
$mail->addAddress('[email protected]', 'Joe User');
$mail->addAddress('[email protected]'); 
$mail->addReplyTo('[email protected]', 'Information');
$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');
$mail->WordWrap = 50; 
$mail->isHTML(true); 
$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';}

that is my code it working in local but not working in live server

i did all setting in my php.ini file like smtp and user password but still not working so please give me proper solution or code that working in live server

this is error

2016-07-07 17:23:09 SMTP ERROR: Failed to connect to server: Network is unreachable (101) 2016-07-07 17:23:09 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

2
the .ini settings don't matter. phpmailer isn't using them. you need to check if the gmail server is accessible from the machine you're testing this on.Marc B
Add your phpmailer errorinfo to your question.Progrock
Do you not need to set the port? $mail->Port=587.Progrock

2 Answers

1
votes

when you are in local at that time smtp.gmail.com its working but in live you need your server host address like mail.servername.com

0
votes

You must first of all activate gmail accepting non secure apps