I am trying to create a contact form on my website, and since the PHP Mail function doesn't work reliably, I am using PHPMailer (a well known email sending library).
Here is my script, and I'm pretty sure it works fine, but I get a 504 Garetway Timeout error when trying to connect to smtp.zoho.com !!
- if (isset($_POST['submit'])) {
$subject = strip_tags($_POST['subject']);
$body = strip_tags($_POST['message']);
require(LIBRARY . '/PHPMailer/class.phpmailer.php');
require(LIBRARY . '/PHPMailer/class.smtp.php');
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.zoho.com";
$mail->Port = 465;
$mail->SMTPDebug = 2;
//Provide username and password
$mail->Username = "webmaster@mydomain.com";
$mail->Password = "PWPWPWPWP";
//From email address and name
$mail->From = "webmaster@mydomain.com";
$mail->FromName = "Mailer";
$mail->IsHTML(false);
//To address and name
$mail->addAddress("myemail@mydomain.com"); //Recipient name is optional
//Address to which recipient will reply
$mail->addReplyTo("myemail@mydomain.com", "Reply");
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AltBody = $body;
if(!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent successfully";
}
}
I'm confident my script is correct, because when I try to simply ping smtp.zoho.com from the command line I get this:
- --- smtp.zoho.com ping statistics ---
11 packets transmitted, 0 received, 100% packet loss, time 9999ms
No wonder I can't send mail, zoho is not responding and causing my script to timeout. How do I fix this?