简体   繁体   中英

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.

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. 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. In postfix this is configured as per the 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:

$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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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