简体   繁体   English

在Windows上使用PHP通过中继发送邮件

[英]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: 我所做的事情:

  • I have setup and validated my mailgun settings. 我已经设置并验证了我的mailgun设置。
  • I have tested sending and receiving emails via the server without the relay (works fine). 我已经测试了在没有中继的情况下通过服务器发送和接收电子邮件的方式(工作正常)。

My dilemma: 我的困境:

  • At one stage I am going to have to state the relay information, such as the authentication or hostname. 在一个阶段,我将必须声明中继信息,例如身份验证或主机名。 So far, i see two place where i can declare this - see below: 到目前为止,我在两个地方可以声明这一点-见下文:

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.

相关问题 在IIS 7上使用PHP发送邮件-Windows 2008 Server - Sending Mail using PHP on IIS 7 - Windows 2008 Server 使用php mailer邮件成功从localhost xamp发送,但无法在生产Windows主机中发送 - using php mailer mail send from localhost xamp successfully but failed to sending in production windows hosting 通过SMTP发送邮件 - Sending mail via smtp PHP在Windows上发送邮件,导致它在发送电子邮件后“挂起” - PHP send mail on windows causing it to 'hang' after sending email 我如何设置Socat在cygwin上通过以太网在rapberry pi和Windows之间中继数据 - How to I set up Socat to relay data between rapberry pi and Windows using cygwin via ethernet Windows Apache和PHP上通过Wordpress的SSL SMTP邮件不起作用 - SSL SMTP mail on Windows Apache and PHP via Wordpress not working 使用Gmail发送邮件 - Sending mail using Gmail 执行Powershell命令以获取Megaraid状态并使用Windows2012中的任务计划程序将输出发送到邮件 - Executing powershell command for getting megaraid status and sending output to mail using task scheduler in windows2012 PHP mail()在Windows(IIS)上不起作用 - PHP mail() NOT working on Windows (IIS) PHP:如何使用Windows Task Scheduler发送POST数据? - PHP: How to sending the POST data using Windows Task Scheduler?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM