PHP 中的邮件转发
我正在为网站开发动态邮件转发组件。
这个概念是 - 用户将发送一封包含任意内容的电子邮件到服务器上的特殊电子邮件地址 - 根据“收件人”和“主题”行内容,系统会将电子邮件转发到一组(外部)电子邮件地址,这些地址是从
我在共享网络主机(Bluehost)上运行的 mysql 数据库中提取的,因此我我认为我没有对邮件基础设施的任何高级访问权限来为我执行此操作(例如,没有 .forward 文件)。目标电子邮件列表是动态的,因此我无法使用 cPanel 设置静态转发。
我有传入的邮件发送到 PHP 脚本,但处理看起来具有挑战性,特别是对于 MIME 部分 - 多部分、附件等。我已经查看了 PEAR Mail / MIME 内容,但完全解码和重新处理似乎有点过分了对消息进行编码...
有什么提示吗?
I am developing a dynamic mail forwarding component for a website.
The concept is that
- a user will send an email with arbitrary content to a special email address on the server
- based on the "to" and "subject" line content, the system will forward the email to a group of (external) email addresses that are pulled from a mysql database
I'm running on a shared webhost (Bluehost), so I don't think I have any advanced access to the mail infrastructure to do this for me (no .forward files, for example). The target email list is dynamic, so I can't use cPanel to set up static forwarding.
I have the incoming mail coming to a PHP script, but the processing looks challenging, especially for the MIME parts - multipart, attachments, etc. I have looked at the PEAR Mail / MIME stuff, but it seems overkill to completely decode and re-encode the msg...
Any tips?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用 phpMailer 从 PHP 发送电子邮件。
几年前我在 mod_perl 中实现了完全相同的概念。请注意,如果您发送的邮件量很大,您的大部分外发电子邮件可能会被阻止。如果您的系统可能被黑客入侵(这听起来至少是合理的),垃圾邮件发送者可能会找到它并使用您的系统,这将导致您的所有外发电子邮件被阻止。
由于垃圾邮件和垃圾邮件过滤器,发送电子邮件比应有的困难(如果仅考虑技术)。如今,我经常发现编写使用第三方服务实际发送电子邮件、通过 API 提供地址的代码更容易。我最近在 MailChimp 和 Contactology API 方面运气不错。
编辑:至于传入的电子邮件:如果您没有处于共享托管的情况下,那就不会那么难 - 只需捕获它,剥离标头,然后将其传回到新地址。我想在这一点上我必须同意 Conrad 的观点——共享主机 PHP 脚本似乎是尝试解决此问题的一个相当次优的环境。如果您无法使用 system() 将其直接通过邮件基础设施传回,我认为您必须完全解析传入的电子邮件并重新组装它。
I use phpMailer for sending email from PHP.
I implemented exactly the same concept in mod_perl a few years back. Be aware that much of your outgoing email will likely be blocked if you send a significant volume. And if your system can be hacked (and that sounds at least plausible), spammers may find it and use your system, which would then lead to all your outgoing email being blocked.
Sending email is more difficult than it should be (if considering only the tech) thanks to spam and spam filters. These days I often find it easier to write code which uses a third-party service to actually send the emails, feeding the addresses over an API. I've had good luck with MailChimp and Contactology APIs recently.
EDIT: as for the incoming email: If you weren't in a shared hosting situation, it wouldn't be that hard - simply capture it, strip the headers, and pipe it back out to a new address. I'd have to agree with Conrad I guess on that point -- a shared host PHP script seems like a rather sub-optimal environment to try and solve this problem. If you can't use system() to pipe it back out directly the the mail infrastructure, I think you do have to completely parse the incoming email and reassemble it.