我正在使用 phpMailer 设计一个简单的联系我们表单。数据正确地传递给 PHP,但电子邮件永远不会发送。我尝试查看错误信息,但它是空的。有什么想法吗?提前致谢!
<?php
require_once('email/mail/class.phpmailer.php');
$email_to = 'myEmail';
$email_subject = 'Contact form';
$fname = $_POST['firstname'];
$lname = $_POST['lastname'];
$email = $_POST['email'];
$dob = $_POST['dob'];
$subject = $_POST['subject'];
$comments = $_POST['comments'];
$mailer = new PHPMailer(true);
$mailer->Host = '**********';
$mailer->Username = '********';
$mailer->Password = '*********';
$mailer->SMTPAuth = true;
$mailer->AddAddress($email_to);
$mailer->SMTPDebug = false;
$mailer->IsSMTP();
$mailer->FromName = 'Contact Page';
$mailer->From = "**********";
$mailer->Sender = '**********';
$mailer->Subject = $email_subject;
$mailer->Body = "
Source: Contact Page
Name: ".$fname. " ".$lname."
Email: ".$email."
Date of Birth: ".$dob."
Subject: ".$subject."
Comments: ".$comments;
echo "Data received";
if(!$mailer->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>
输出是:
Data receivedMessage was not sent.Mailer error:
输出print_r($mailer)
:
PHPMailer Object (
[Priority] => 3
[CharSet] => iso-8859-1
[ContentType] => text/plain
[Encoding] => 8bit
[ErrorInfo] =>
[From] => contact@blah.com
[FromName] => Contact Page
[Sender] => contact@blah.com
[Subject] => Contact form
[Body] =>
Source: blah
Name: Derp McDerpson
Email: derpallday@gmail.com
Date of Birth: 1/1/2000
Subject: The things!
Comments: fix them
[AltBody] =>
[WordWrap] => 0
[Mailer] => smtp
[Sendmail] => /usr/sbin/sendmail
[PluginDir] =>
[Version] => 1.73
[ConfirmReadingTo] =>
[Hostname] =>
[Host] => mail.authsmtp.com
[Port] => 25
[Helo] =>
[SMTPAuth] => 1
[Username] => blah
[Password] => blah
[Timeout] => 10
[SMTPDebug] =>
[SMTPKeepAlive] =>
[smtp] =>
[to] => Array (
[0] => Array (
[0] => blah@blah.com
[1] => blah
)
)
[cc] => Array ( )
[bcc] => Array ( )
[ReplyTo] => Array ( )
[attachment] => Array ( )
[CustomHeader] => Array ( )
[message_type] =>
[boundary] => Array ( )
[language] => Array ( )
[error_count] => 0
[LE] =>
)