PHPMailer $mail->From 标头不适用于 gmail [英] PHPMailer $mail->From headers not working with gmail

查看:23
本文介绍了PHPMailer $mail->From 标头不适用于 gmail的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 PHP 邮件程序类

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.

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();

解决方案

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

这篇关于PHPMailer $mail->From 标头不适用于 gmail的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆