[英]Sending mail via relay using PHP on Windows
I am using PHPMailer (via SMTP) to send out emails via my websites. 我正在使用PHPMailer(通过SMTP)通过我的网站发送电子邮件。 I am using a windows 2012 server as my mail server which is using Hmailserver.
我正在使用Windows 2012服务器作为使用Hmailserver的邮件服务器。 I am using Mailgun to relay my emails.
我正在使用Mailgun中继我的电子邮件。
Things I have done: 我所做的事情:
My dilemma: 我的困境:
1) Specify via PHPMailer script: 1)通过PHPMailer脚本指定:
$mail->IsSMTP();
$mail->host = "smtp.mailgun.org";
$mail->Username = "username";
$mail->Password = "password";
2) Specify in hmailserver admin (on the server): 2)在hmailserver管理员(在服务器上)中指定:
http://puu.sh/cJLpk/c3d548981c.png http://puu.sh/cJLpk/c3d548981c.png
Which way do I do this if I want to relay all my emails? 如果我想中继所有电子邮件,该怎么做?
Using your local mail server (hmailserver) as a relay will be faster (at least for your client scripts) and much more reliable. 使用本地邮件服务器(hmailserver)作为中继将更快(至少对于您的客户端脚本而言)并且更加可靠。 It should be configured to point at mailgun, as in your screen shot.
如屏幕截图所示,应将其配置为指向mailgun。 Mailgun should provide you with credentials that you can use for authenticating the relay.
Mailgun应该为您提供可用于验证中继的凭据。
When you send with PHPMailer, you should configure it to point at localhost, like this: 使用PHPMailer发送时,应将其配置为指向localhost,如下所示:
$mail->IsSMTP();
$mail->Host = 'localhost';
$mail->Username = "username";
$mail->Password = "password";
(You may not need username and password for your local server). (您可能不需要本地服务器的用户名和密码)。 Though it may sound odd, using SMTP to localhost is often faster than calling a local sendmail binary (or using PHP's
mail()
function). 尽管听起来很奇怪,但使用SMTP到本地主机通常比调用本地sendmail二进制文件(或使用PHP的
mail()
函数)更快。
In your original code you had host
instead of Host
- PHP is case-senetive for property names, so that would have been failing if that was your real code. 在你原来的代码你有
host
,而不是Host
- PHP是区分senetive的属性名称,所以那会是失败的,如果这是你真正的代码。
That should be all there is to it. 那应该就是它的全部了。
The only other complication is if hmailserver is also sending messages that are not supposed to go through mailgun, in which case you will need to get further into your hmailserver config. 唯一的其他麻烦是,如果hmailserver也发送了不应该通过mailgun发送的消息,在这种情况下,您将需要进一步进入hmailserver配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.