2016-09-26 111 views
1

我有這樣的形式,即發送罰款在當地,但是當我把它上傳到HostGator的我收到以下錯誤消息PHP SMTP自定義聯繫人形式

Mailer Error: Could not instantiate mail function.

我的PHP代碼

<?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!"; 
    } 

} 
?> 

我已經和我的主人說過話了,他們說沒有支持處理這些事情,但說我的港口和主機是正確的。

所以現在我很困惑。有什麼明顯的我失蹤?

+1

郵件功能可以在您的託管服務提供商被阻止。聯繫他們的支持,以確保它不被阻止。 – Jer

+0

似乎我缺少$ mail-> IsSMTP();從我的SMTP配置部分。歡呼的鏈接。幫我找到了我的問題。 – ltjfansite

+0

不客氣:-) _http://stackoverflow.com/questions/30648462/phpmailer-error-could-not-instantiate-mail-function_ – Jer

回答

0

只是爲了讓你知道是否有人發現這一點,我的問題是我缺少$ mail-> IsSMTP();從我的配置。

的SMTP配置部分應該如下

<?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!"; 
    } 

} 
?> 
相關問題