I have been facing trouble with phpmailer on live server as it is giving me error smtp connect() failed (Netword is unreachable 101) but working good on localhost please someone guide me how to fix it i have been tried different approaches but nothing worked...
phpmailer code
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>";
}
}
?>
Try to catch the error. maybe that answer could be useful. PHP - Error handling
you can make a more comfortable search
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.