PHP 邮件程序 - SMTP GMAIL 身份验证

标签 php smtp gmail phpmailer

我的 PHP MAILER 功能有问题。我正在使用 GMAIL SMTP 身份验证来发送电子邮件,并且它工作得很好,但我想将“发件人”电子邮件设置为“[email protected]”,但它无法正常工作。

我使用下面的代码来设置“发件人”电子邮件

$mail             = new PHPMailer();

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "mail.gmail.com"; // SMTP server
$mail->SMTPDebug  = 0;                     // enables SMTP debug information (for testing)
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$mail->Username   = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1f6b7a6c6b5f78727e7673317c7072" rel="noreferrer noopener nofollow">[email protected]</a>";  // GMAIL username
$mail->Password   = "test@123";  

$mail->SetFrom("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="620f1b0b0622060d0f030b0c0c030f074c010d0f" rel="noreferrer noopener nofollow">[email protected]</a>","Domian");

它向我显示默认电子邮件[email protected]而不是[email protected]

请帮帮我。

提前致谢!

最佳答案

Gmail 会重写通过 smtp.gmail.com 发送的邮件的 header ,将发件人地址替换为与您用于发送邮件的 Gmail 帐户关联的 Gmail 地址。有关详细信息和可能的解决方法,请参阅:http://lifehacker.com/111166/how-to-use-gmail-as-your-smtp-server

关于PHP 邮件程序 - SMTP GMAIL 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18101769/

相关文章:

php - 出现错误,如 imap_open() : Couldn't open stream in server

php - 将自定义变量添加到 Gmail 收件箱中已有的电子邮件 header

php - SoapFault 未经授权 - 连接到 Purolator Web 服务

php - PHP添加好友功能

php - 在 php 中按字母顺序显示 html li 元素

php - SMTP 服务器响应 : 530 5. 7.0 必须先发出 STARTTLS 命令

php - 如何设置从另一个页面通过 AJAX 调用的下拉列表的默认值?

java - 通过 SMTP Gmail Oauth2 问题发送邮件

java - 如何使用带有 OAuth2 身份验证的 Gmail SMTP 使用 java 邮件发送邮件?

php - 为时间敏感的图像覆盖 Gmail 图像缓存(或设置较短的时间限制)