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
require 'mail/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'myemail@gmail.com';
$mail->Password = 'mypassword';
$mail->SMTPSecure = 'tls';
$mail->From = 'myemail@gmail.com';
$mail->FromName = 'Mailer';
$mail->addAddress('myemail@gmail.com', 'Joe User');
$mail->addAddress('myemail@gmail.com');
$mail->addReplyTo('myemail@gmail.com', 'Information');
$mail->addCC('myemail@gmail.com');
$mail->addBCC('myemail@gmail.com');
$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';}
当您当时在本地时 smtp.gmail.com 它可以正常工作但在现场您需要您的服务器主机地址,例如 mail.servername.com
您必须首先激活接受非安全应用程序的 gmail
Use real email for sender and receiver 'Make sure of the password'
<\/blockquote>
<\/li><\/ol>
$mail->Port = 465 ; \/\/ or 587
<\/blockquote>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.