1

I have this form, that send fine locally, but when i upload it to hostgator i get the following error message

Mailer Error: Could not instantiate mail function.

my php code is

<?php

if(isset($_POST['submit'])){

    require 'PHPMailer/PHPMailerAutoload.php';

    // Send mail
    $mail = new PHPMailer();

    // Data received from POST request
    $name = stripcslashes($_POST['tbName']);
    $emailAddr = stripcslashes($_POST['tbEmail']);
    $company = stripcslashes($_POST['tbCompany']);
    $comment = stripcslashes($_POST['taMessage']);
    $subject = stripcslashes($_POST['tbSubject']);  

    // SMTP Configuration
    $mail->SMTPAuth = true; 
    $mail->Host = "gator3209.hostgator.com"; // SMTP server
    $mail->Username = "****@*****.com";
    $mail->Password = "***********";
    $mail->SMTPSecure = 'tls';   
    $mail->Port = 25; 

    $mail->AddAddress('****@*****.com');
    $mail->From = "****@*****.com";
    $mail->FromName = "Website Contact Form - " . $name;
    $mail->Subject = $subject;

    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';    
    $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
    $mail->MsgHTML("Name:" . $name . "<br /><br />Email:" . $emailAddr. "<br /><br />Company:" . $company. "<br /><br />Subject:" . $subject. "<br /><br />" . $comment);

    $message = NULL;
    if(!$mail->Send()) {
        $message = "Mailer Error: " . $mail->ErrorInfo;
    } else {
        $message = "Message sent!";
    }

}
?>

I have spoken to my host and they said its not within there support to deal with these things, but said my port and host are correct.

So now I'm rather confused. is there anything obvious I'm missing?

ltjfansite
  • 440
  • 1
  • 7
  • 19
  • 1
    The mail function may be blocked at your hosting provider. Contact their support to ensure it's not blocked. – node_modules Sep 26 '16 at 14:42
  • Seems i was missing $mail->IsSMTP(); from my SMTP config section. Cheers for the link. helped me find my problem. – ltjfansite Sep 26 '16 at 14:53
  • You're welcome :-) _http://stackoverflow.com/questions/30648462/phpmailer-error-could-not-instantiate-mail-function_ – node_modules Sep 26 '16 at 14:53

1 Answers1

0

Just to let you know if anyone finds this, my problem was i was missing $mail->IsSMTP(); from my config.

the SMTP config section should be as follows

<?php

if(isset($_POST['submit'])){

    require 'PHPMailer/PHPMailerAutoload.php';

    // Send mail
    $mail = new PHPMailer();

    // Data received from POST request
    $name = stripcslashes($_POST['tbName']);
    $emailAddr = stripcslashes($_POST['tbEmail']);
    $company = stripcslashes($_POST['tbCompany']);
    $comment = stripcslashes($_POST['taMessage']);
    $subject = stripcslashes($_POST['tbSubject']);  

    // SMTP Configuration
    $mail->SMTPAuth = true; 
    $mail->IsSMTP();
    $mail->Host = "gator3209.hostgator.com"; // SMTP server
    $mail->Username = "****@*****.com";
    $mail->Password = "***********";
    $mail->SMTPSecure = 'tls';   
    $mail->Port = 25; 

    $mail->AddAddress('****@*****.com');
    $mail->From = "****@*****.com";
    $mail->FromName = "Website Contact Form - " . $name;
    $mail->Subject = $subject;

    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';    
    $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
    $mail->MsgHTML("Name:" . $name . "<br /><br />Email:" . $emailAddr. "<br /><br />Company:" . $company. "<br /><br />Subject:" . $subject. "<br /><br />" . $comment);

    $message = NULL;
    if(!$mail->Send()) {
        $message = "Mailer Error: " . $mail->ErrorInfo;
    } else {
        $message = "Message sent!";
    }

}
?>
ltjfansite
  • 440
  • 1
  • 7
  • 19