【问题标题】:PHP SMTP Custom contact formPHP SMTP 自定义联系表
【发布时间】:2017-02-03 23:06:12
【问题描述】:

我有这个表格,可以在本地发送,但是当我将它上传到 hostgator 时,我收到以下错误消息

Mailer 错误:无法实例化邮件功能。

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

}
?>

我已经和我的主机谈过了,他们说它不支持处理这些事情,但说我的端口和主机是正确的。

所以现在我很困惑。我有什么明显的遗漏吗?

【问题讨论】:

  • 您的托管服务提供商可能会阻止邮件功能。联系他们的支持以确保它没有被阻止。
  • 好像我错过了 $mail->IsSMTP();从我的 SMTP 配置部分。为链接干杯。帮助我找到了我的问题。

标签: php forms email smtp


【解决方案1】:

只是让你知道如果有人发现这个,我的问题是我错过了 $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!";
    }

}
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-23
    • 1970-01-01
    • 1970-01-01
    • 2020-07-18
    • 2015-04-21
    • 1970-01-01
    • 2012-10-22
    相关资源
    最近更新 更多