从 PHP 发送电子邮件时使用 SSL/TLS

发布于 2024-12-07 19:22:53 字数 791 浏览 0 评论 0 原文

我对电子邮件服务器和使用 PHP 发送电子邮件非常陌生...

是否可以在将电子邮件发送到收件人的邮件服务器之前使用 SSL 或 TLS 加密从我的服务器上的 PHP 脚本发送的电子邮件?

我需要确保只有目标收件人才能阅读电子邮件,以防传输在发送到邮件服务器的过程中被拦截。

我不确定这是否可能,因为收件人的邮件服务器不知道公钥,对吧?那么它如何解密电子邮件呢?

作为背景,我实际上并没有为任何人托管电子邮件帐户 - 因此这不是用户通过我的服务器进行身份验证并为在那里托管的他们下载电子邮件的情况。我只有一个脚本触发从“[email protected]"(这不是服务器上的真实电子邮件地址,因此您无法回复它)到用户的真实电子邮件地址(我的应用程序知道) 。我需要一种方法来确保这封电子邮件从我的服务器上的 PHP 安全发送到收件人邮件服务器。

我已经查看了 PHP 中的 mail() 函数以及 PHPMailer 类 - 但我不确定如何配置这些方法中的任何一个来安全地发送电子邮件。

我所有的研究只是展示如何在我的服务器上安装 SSL,以便用户可以安全地下载存储在我的服务器上的电子邮件 - 这不是我在这里想要做的。

我正在运行 Centos5.7,我相信它安装了邮件服务器,尽管我不确定 PHP 是否实际上默认使用它。

感谢您的帮助!

I am very new to email servers and sending email with PHP...

Is it possible to have email sent from a PHP script on my server encrypted using SSL or TLS before it is sent to the recipient's mail server?

I need to ensure only the intended recipient can read the email, in case the transmission is intercepted on its journey to their mail server.

I am not sure if this is possible, as the recipient's mail server would not know the public key right? So how could it decrypt the email?

As background, I am not actually hosting email accounts for anyone - so it is not a case of the users authenticating with my server and downloading emails for them hosted there. I just have a script triggering an alert email to be sent from "[email protected]" (which is not a real email address on the server so you can't reply to it) to the user's real email address (which my application knows). I need a way to make sure this email is securely sent from PHP on my server, to the recipients mail server.

I have looked at the mail() function in PHP, as well as the PHPMailer class - but I am not sure how I would configure either of these methods to securely send the email.

All my research just shows how to install SSL in on my server so users can securely download email stored on my server - which is not what I am trying to do here.

I am running Centos5.7 which I believe has a mail server installed, though I am not sure if PHP actually uses that by default..

Thanks for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笙痞 2024-12-14 19:22:53

您无法保证电子邮件将送达收件人的邮箱。 唯一地方是邮件客户端和发送 SMTP 服务器之间的连接。在那之后,一切就完全脱离了你的掌控。

如果您需要保证电子邮件的隐私,则必须对电子邮件正文进行加密。您需要的是 S/MIME 或 PGP 消息。并不是说这仍然使一些信息公开可用 - 邮件正文将被加密,但地址信息仍然必然是可读的 - 中间邮件服务器仍然需要知道如何传递邮件

You can't guarantee that an email will be delivered to the recipient's mailbox. The ONLY place you is the connection between your mail client, and your outgoing SMTP server. After that, it's utterly out of your hands.

If you need to guarantee privacy on the email, you'll have to encrypt the body of the email. What you want is an S/MIME or PGP message. Not that this still leaves SOME information publicly available - the mail body will be encrypted, but addressing information will necessarily still be readable - intermediate mail servers still need to know how to deliver the mail

萤火眠眠 2024-12-14 19:22:53

您正在寻找的加密类型不是 SSL/TSL,后者用于加密客户端 (PHP) 和将发送该数据的 SMTP 服务器之间的传输。 SSL/TLS 不保证数据在到达其端点的整个过程中都会被加密。事实上,几乎肯定不会,因为数据沿途在 SMTP 服务器和交换机之间中继。

相反,您正在寻找 PGP 加密,它可以使用 GnuPG 函数 在 PHP 中实现。您必须使用收件人的公钥对消息进行加密。然后只能使用由接收者单独持有的接收者私钥来解密和读取它。

要在 mail() 中实现此功能,您首先需要加密消息正文,然后将加密的 ascii 装甲块作为其第三个参数传递给 mail()。消息头不会被加密,只有正文。

附录

大多数银行和医疗服务(至少在美国)处理安全消息传输的方式根本不是发送电子邮件。相反,必须保证安全的消息存储在网站的用户“收件箱”中。用户必须(通过 SSL)登录网站才能阅读安全收件箱中的邮件。发送电子邮件只是为了通知用户有新消息正在等待。

The type of encryption you are looking for is not SSL/TSL, which is used to encrypt transmission between the client (PHP) and the SMTP server which will send it on. SSL/TLS makes no guarantee that the data will be encrypted all the way to its endpoint. In fact, it almost certainly won't be as the data is relayed between SMTP servers and switches along the way.

Instead you are looking for PGP encryption, which can be implemented in PHP using the GnuPG functions. You must encrypt the message using your recipient's public key. It can then only be decrypted and read with the recipient's private key, held by the recipient alone.

To implement this in mail(), you would first encrypt the message body, then pass the encrypted, ascii armored block to mail() as its third parameter. Message headers will not be encrypted, only the body.

Addendum

The way secure message transmission is handled by most banks and medical services (in the US, anyway) is not to send email at all. Instead, messages which must be kept secure are stored in a user's "inbox" with the website. The user must login (over SSL) to the website to read messages in the secure inbox. Email is only sent to notify the user that new messages are waiting.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文