[英]SMTP Connect failed PhpMailer on live Server
我一直在使用实时服务器上的phpmailer遇到麻烦,因为它给我错误smtp connect()失败(Netword无法访问101),但是在localhost上运行良好,请有人指导我如何解决它,我尝试了不同的方法,但没有任何效果。 ..
phpmailer代码
require '/home/schoswiy/public_html/assets/PHPMailer-master/src/PHPMailer.php';
require '/home/schoswiy/public_html/assets/PHPMailer-master/src/SMTP.php';
require '/home/schoswiy/public_html/assets/PHPMailer-master/src/Exception.php';
set_time_limit(0);
if(isset($_POST['send_message'])){
$name = trim($_POST['name']);
$subject = trim($_POST['subject']);
$email = trim($_POST['email']);
$message = trim($_POST['message']);
$mail = new PHPMailer\PHPMailer\PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->SMTPAuth = true;
$mail->Port= 465;
$mail->SMTPDebug = 4;
$mail->Username ='myemail@gmail.com';
$mail->Password = 'pass';
$mail->SMTPSecure = 'ssl';
$mail->setFrom('myemail@gmail.com', 'xyz');
$mail->addReplyTo($email, $name);
$mail->addAddress('myemail@gmail.com');
$mail->Subject = $subject;
$mail->Body = $message;
if($mail->send()){
$_SESSION['msg'] = 'Message Send Successfully';
header("location:contact-us.php");
echo "messsage Send";
}
else {
echo "<script type='text/javascript'> alert('Failed to send')</script>";
}
}
?>
尝试捕获错误。 也许那个答案可能有用。 PHP-错误处理
您可以进行更舒适的搜索
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.