简体   繁体   English

PHP通过具有Internet连接的代理服务器发送没有Internet连接的电子邮件

[英]PHP send email without internet connection via proxy server which have internet connection

我有没有Internet运行的PHP应用程序。我想使用此应用程序通过具有有效Internet连接的本地代理服务器发送电子邮件。

This is a very broad question that's more suited to Server Fault than here. 这是一个非常广泛的问题,比这里更适合服务器故障。 SMTP's store-and-forward architecture means that proxying email isn't especially easy, and for the most part it's reserved for load balancing across clusters of inbound servers in high-availability situations, rather than outbound which is considerably less reliable. SMTP的存储转发体系结构意味着代理电子邮件并不是特别容易,并且在大多数情况下,它保留用于在高可用性情况下跨入站服务器群集进行负载平衡,而不是可靠性较差的出站。

The way you would normally go about this is instead to use a relay rather than a proxy. 通常,解决此问题的方法是使用中继而不是代理。 You send to the relay, then the relay sends onwards to the internet. 您发送到中继,然后中继继续发送到Internet。 Install a mail server on your proxy server and configure it as a relay for your local server's mail server. 在代理服务器上安装邮件服务器,并将其配置为本地服务器的邮件服务器的中继。 There are many guides on how to do this, such as this one . 有关如何执行此操作的指南很多,例如本指南 Nearly all such guides assume that you are sending via some external service like gmail which requires authentication, so you'll see lots of references to sasl and the line, however, since it's on your local network you can instead whitelist its IP so you can relay without authentication. 几乎所有此类指南都假定您正在通过需要验证的gmail之类的外部服务进行发送,因此您会看到大量有关sasl和线路的引用,但是,由于它位于本地网络中,因此您可以将其IP列入白名单,以便没有身份验证的中继。 In postfix this is configured as per the docs . 在postfix中,根据docs进行配置。

When you've done that, test it by sending a message to yourself using a command line mail client from your server: 完成此操作后,通过使用服务器上的命令行邮件客户端向自己发送消息来进行测试:

echo "test" | mail -s "Relay test" -a "From: you@example.com" recipient@example.com

You can trace the delivery of that message from your local server, through the relay, and on to your own mail server by reading the log files of each. 您可以通过读取每个邮件的日志文件来跟踪从本地服务器,通过中继到您自己的邮件服务器的邮件传递。

Once you know your infrastructure is working, you can use it from PHPMailer in two ways: talk directly to the relay server: 一旦知道您的基础结构正在运行,就可以通过两种方式从PHPMailer中使用它:直接与中继服务器通信:

$mail->isSMTP();
$mail->Host = '10.0.0.2'; //Your relay's internal IP
$mail->SMTPAuth = false; //Don't need authentication if whitelisted
//Prevent PHPMailer trying to use encryption; it won't work with a literal IP
$mail->SMTPAutoTLS = false;
$mail->SMTPSecure = false;

Or use your server's local mail server to do the relaying for you: 或使用服务器的本地邮件服务器为您进行中继:

$mail->isSMTP();

(default properties will work, so all you need to do is enable SMTP). (默认属性将起作用,因此您需要做的就是启用SMTP)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM