我正在使用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] =>
)
答案 0 :(得分:0)
我相信你错过了实际的发送文件:$ mailer-&gt; Send();尝试添加并运行它
答案 1 :(得分:0)
解决了,我试图使用“from”和“sender”的错误值,我的服务器设置不正确。感谢Jim和Patrick的意见。
答案 2 :(得分:-1)
First Name“。$ _ POST ['fname']。”company“。$ _ POST ['company']。”Email“。$ _ POST ['email']。”Telephone“。$ _ POST ['telelphone'] 。“评论” 。$ _ POST [ '评论'] “”; $标题= “MIME-版。”:1.0 \ r \ n “个; $夏理=” 内容类型:文本/ HTML;沙雷= ISO-8859-1 \ r \ N“; $标题=。 “FROM:”。$ _ POST [ '电子邮件'] “\ r \ n” 个;邮件($到,$主题,$体,$头);回声“