dongshuzui0335 2016-08-01 13:51
浏览 37
已采纳

PhpMailer未收到用户名和电子邮件地址[关闭]

Sender email and name was not received. PhpMailer message says email was successfully sent, but I cant get the sender email or sender name. I received only the body and subject.

Thanks

<?php
require 'PHPMailerAutoload.php';
$name = $_POST['fname'];
$mail = $_POST['email'];
$subject = $_POST['subj'];
$message = $_POST['mssg'];


$mail = new PHPMailer;

$mail->isSMTP();     // Set mailer to use SMTP
$mail->Host = 'xxxxhost.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;   // Enable SMTP authentication
$mail->Username = 'xxxxxx@host.com';       // SMTP username
$mail->Password = 'xxxxxxxxxxxx';             // SMTP password
$mail->SMTPSecure = 'tls';  // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25; // TCP port to connect to

$mail->setFrom($mail, $name); // this value not received 
// Add a recipient
$mail->addAddress('support@example.com'); // Name is optional


$mail->isHTML(true);   // Set email format to HTML

$mail->Subject = $subject;
$mail->Body    = $message;


if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
  • 写回答

2条回答 默认 最新

  • duandi2853 2016-08-01 15:07
    关注

    You question isn't very clear, but I'll take a guess at what you're asking.

    Don't use the submitter's email address as the From address. It's forgery and will usually mean you get rejected for SPF violations or end up in spam folders. Gmail doesn't let you use arbitrary from addresses for this reason (though you can predefine aliases in gmail prefs) and it will simply use your Username address instead.

    Set the submitter's address as a reply-to (see addReplyTo() in PHPMailer) and your own address as the from address. This way you won't be forging anything, and replies will go to the right place. Like this:

    $mail->addReplyTo($_POST['email'], $_POST['name']);
    $mail->setFrom('me@example.com', 'My Name');
    

    It's a good idea to put those values into the message body as well in case it's an invalid email address due to a simple typo, for example user @example.com. The reply-to will not work, but you'll still have the data.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 根据以下文字信息,做EA模型图
  • ¥15 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
  • ¥15 vscode程序一直报同样的错,如何解决?
  • ¥15 关于使用unity中遇到的问题
  • ¥15 开放世界如何写线性关卡的用例(类似原神)
  • ¥15 关于并联谐振电磁感应加热
  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥60 关机时蓝屏并显示KMODE_EXCEPTION_NOT_HANDLED,怎么修?
  • ¥66 如何制作支付宝扫码跳转到发红包界面