问题描述
我想通过 gmail 向 B 发送一封电子邮件,其中包含 HEADER 和 CONTENT.
I want to send an email from A to B,with HEADER and CONTENT through gmail.
如何通过 PHP 做到这一点?
How to do that by PHP?
我已经指定了FROM(来自@example.com),但是当我收到电子邮件时,它仍然来自我的gmail帐户(abc@gmail.com).
I've specified the FROM(from@example.com),but when I receive the email,it's still from my gmail account(abc@gmail.com).
$mail->From = "from@example.com";
$mail->FromName = "Mailer";
$mail->AddAddress("abc12@163.com", "Josh Adams");// name is optional
$mail->AddReplyTo("abc12@qq.com", "Information");
如何更改 FROM 部分?
推荐答案
简短的回答 - 你不能.
The short answer - you can't.
Google 会将您通过其 SMTP 服务发送的邮件中的 From 和 Reply-To 标头重写为与您的 gmail 帐户相关的值.
Google rewrites the From and Reply-To headers in messages you send via it's SMTP service to values which relate to your gmail account.
gmail 的 SMTP 功能并非旨在成为开放或中继服务.如果它允许 From 标头使用任何值,则会大大削弱 Google 在垃圾邮件服务中的地位,因为无法验证发件人的凭据.
The SMTP feature of gmail isn't intended to be an open or relay service. If it allowed any values for the From header, it would significantly dilute Google's standing with spam services, as there would be no way to verify the credentials of the sender.
您需要考虑替代方案.您计划在完成后如何托管您的脚本/应用程序/网站:几乎每个托管解决方案(共享/vps/专用服务器)都将预先配置电子邮件传输解决方案:无论是 *nix 上的 sendmail 或 postfix,还是 IIS在 Windows 上.
You need to consider alternatives. How are you planning to host your script/application/website when it's finished: virtually every hosting solutions (shared/vps/dedicated server) will come pre-configured with an email transfer solution: be it sendmail or postfix on *nix, or IIS on Windows.
如果您打算使用 gmail,那么您可以:
If you are intent on using gmail then you could:
- 设置专用的myapp@gmail.com"帐户
- 如果您拥有应该发送的域,请使用免费 gmail 域,并且设置一个myapp@mydomain.com"帐户.
- Setup a dedicated "myapp@gmail.com" account
- If you own the domain you are supposedly sending from, use the free gmail for domains, and setup a "myapp@mydomain.com" account.
====
建议 GMail 确实允许通过不同地址发送.据我所知,这是通过 GMail wep 应用程序发送,并利用您现有的外部 SMTP 服务器,这与原始问题无关.
It was suggested that GMail does allow sending via different addresses. As far as I can tell, this is for sending via the GMail wep app, and utilises your existing external SMTP server, which is not relevant to the original question.
====
看来这仍然获得了少量选票.快速更新.
Seeing as this is still getting a trickle of votes. A quick update.
Google 已撤消了针对域的免费 GMail.周围还有很多其他免费服务.值得注意的是 Mandrill - 一种用于交易电子邮件(例如电子商务)的一对一电子邮件服务订单等).它由 MailChimp 运行,他几乎知道关于批量发送电子邮件的所有知识.他们还为您提供每月 12k 的免费费用,这相当不错.
Google have withdrawn their free GMail for domains. There are plenty of other free services around. One of note is Mandrill - a one-to-one email service intended for transactional emails (e.g. ecommerce orders etc.). It's ran by MailChimp, who pretty much know all there is to know about sending email at volume. They also give you 12k/month free, which is rather nice.
这篇关于使用gmail smtp服务器时如何更改发件人地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!