想要从联系表单中获取输入并通过电子邮件发送到地址。使用PHPMailer(GitHub的最新版本)和Google的SMTP。
配置变量
<?php
$host = "smtp.google.com";
$port = 587;
$username = "********@gmail.com";
$password = "********";
?>
表格发送电子邮件脚本
<?php
require_once('PHPMailer-master/class.phpmailer.php');
include('../../../settings/config.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = gethostbyname($host);
$mail->SMTPDebug = 2;
$mail->Port = $port;
$mail->Username = $username;
$mail->Password = $password;
$mail->SetFrom($username, 'Webform');
$mail->AddReplyTo($_POST['email'], $_POST['name']);
$mail->Subject = "CONTACT REQUEST";
$mail->Body = "\nName: " . $_POST['name'] . "\n" . "Email: " .
$_POST['email'] . "\n" . "Subject: " . $_POST['subject'] . "\n"
. "--BEGIN MESSAGE--\n\n" . $_POST['message'] .
"\n\n--END MESSAGE--";
$mail->AddAddress($username);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else { echo "Message sent!"; }
?>
如果我运行这个,我得到一个空白的屏幕,就像有语法错误,它根本不会抛出调试消息。我把它分隔为$ mail-&gt; Send()将代码更改为以下内容:
<?php
.
.
.
/* if(!$mail->Send()) {
.
.
.
} else { . . . } */
echo "some message";
?>
代码将正常运行,如果更改为此消息,将回显一些消息。我不确定问题是什么,我已经改变了各种各样的东西,试图让它工作,但没有任何地方。我的服务器配置是否可能存在问题?
感谢您的任何建议,