dongzheng8463 2013-06-08 15:57
浏览 24
已采纳

PHPMailer $ mail->来自不使用gmail的标头

I'm using the following code to send a mail after a form submission with the PHP mailer class https://github.com/Synchro/PHPMailer. The mail sends and is received successfully. The only thing that isn't wokring is the following:

$mail->From = $email;

$email is the email that a user will enter on the form (it is set with a $_POST variable). I would like the email to appear that it's from the user who filled out the form, so I can hit reply and have it go to their email address.

However, the "from" email address is being set as $mail->Username, i.e. the username from the gmail account that the PHPMailer script is sending from.

enter image description here

What am I doing wrong here, and how do I get the From email header to work?

Also, I am using Gmail to receive the mail-- maybe there's a gmail security setting that won't allow the "From" email to be "faked"???

Thanks!

$email = $_POST['email'];
$name = $_POST['moveName'];

require("class.phpmailer.php");
$mail = new PHPMailer();

$mail->IsSMTP();
$mail->Host = 'ssl://smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = 'example@gmail.com';
$mail->Password = 'password';

$mail->From = $email;
$mail->FromName = $name;
$mail->AddAddress('me@gmail.com');
$mail->AddReplyTo($email, $name);

$mail->IsHTML(true);

$mail->Subject = 'Quote Request';
$mail->Body    = 'hey';

$mail->Send();
  • 写回答

1条回答 默认 最新

  • dtg25862 2013-06-08 17:32
    关注

    With gmail you have to configure an email address as allowed "$mail->from" first. This FAQ entry explains how to do it: https://support.google.com/mail/answer/22370?hl=en

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵