So I have a contact form that uses phpmailer. It sends an email from one Gmail account to another. But I can’t seem to get the receiving email to receive any emails.
The script is hosted on a cpanel (RivalHost) and the domain is on GoDaddy. I asked RivalHost if they were blocking SMTP connections or blocking ports 587 or 465, and they said they weren’t. So I have no idea what’s causing the issue. The script works perfectly fine on my localhost, just not on cpanel
Heres the mailing script:
<?php
$result="";
if(isset($_POST['submit'])){
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->Host='smtp.gmail.com';
$mail->Port=465;
$mail->SMTPAuth=true;
$mail->SMPTSecure='ssl';
$mail->Username='[email protected]';
$mail->Password='*********';
$mail->setFrom('[email protected]');
$mail->addAddress('[email protected]');
$mail->addReplyTo($_POST['email'],$_POST['name']);
$mail->isHTML(true);
$mail->Subject='Contact: '.$_POST['subject'];
$mail->Body='Message: '.$_POST['msg'].'</h1>';
if(!$mail->send()){
$result='something went wrong';
echo $result;
} else {
$result="thank you";
echo $result;
}
}
?>
I was also told to check my MX records, but wasn’t really sure what to change them to, or if I needed to change them at all:
MX 0 ********.com 3599 RBL
2
Answers
Solution 1:
PHPMailer uses exeptions. You can put your code in try/catch block to get exceptions caused emails not to be sent.
Solotion 2:
Are you also using the CSF firewall? If so, check to see if the “SMTP_BLOCK” setting is enabled. If STMP_BLOCK is enable contact to hosting to disable it.
Add this to your settings: