skip to Main Content

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


  1. Solution 1:
    PHPMailer uses exeptions. You can put your code in try/catch block to get exceptions caused emails not to be sent.

    $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch
    
    try {
      //Email information comes here
      $mail->Send();
      echo "Message Sent OKn";
    } catch (phpmailerException $e) {
      echo $e->errorMessage(); //Pretty error messages from PHPMailer
    }
    

    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.

    Login or Signup to reply.
  2. Add this to your settings:

    $mail->isSMTP();
    $mail->SMTPDebug = 2; 
    $mail->SMTPAuth = true;
    if (!$mail->send()) {
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message sent!';
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search