简体   繁体   English

使用PHP Mailer从本地服务器外部的电子邮件地址发送smtp电子邮件

[英]Using PHP Mailer to send smtp emails from an email address outside the local server

I want to use PHPMailer configure the contact page for my website. 我想使用PHPMailer为我的网站配置联系页面。 The prroblem I am facing is that for the script to work, the from address has to be set in the local server eg if my domain is example.com , the from address has to be name@example.com . 我对着prroblem是,脚本工作, 地址在本地服务器如要设定如果我的域名是example.com,从该地址必须name@example.com。 When I set it this way, the script works perfectly. 当我以这种方式设置时,脚本可以完美运行。 the issue I'm having is that being a contact page, the from address has to be the senders email address this there for means that if a customer contacts me with the email address like name@email.com, the script will throw an error similar to the one below: 我遇到的问题是,作为联系人页面,发件人地址必须是发件人的电子邮件地址,这意味着如果客户使用诸如name@email.com的电子邮件地址与我联系,则脚本将引发错误与下面的类似:

SMTP ERROR: DATA END command failed:
550-Your FROM address ( name@email.com , Dev Customer 550-)
must match your authenticated email user ( name@example.com ).

Does anyone have any idea on a way to work around this? 有谁知道解决此问题的方法吗? Or are there any alternatives? 还是有其他选择? I will appreciate any form of assistance offered. 我将不胜感激提供的任何形式的帮助。 Thank you in advance. 先感谢您。

As per Tigger's suggestion, you should never send using the submitter's address as a From address. 根据Tigger的建议,您绝对不应使用提交者的地址作为发件人地址进行发送。 It's forgery, and will make your messages fail SPF checks, causing you no end of delivery problems either with messages bouncing or consigned to spam folders. 这是伪造的,会使您的邮件无法通过SPF检查,从而不会导致邮件退回或委托到垃圾邮件文件夹的传递结束问题。 It's been actively advocated against for at least a decade anyway, and it's also one of the practices that would cause you to be vulnerable to the security hole in PHPMailer fixed back in December. 无论如何,至少十年来一直在积极提倡它,并且它也是一种使您容易受到12月份修复的PHPMailer中的安全漏洞的攻击之一。

Since you've tagged this with PHPMailer, I'll show how to use that to do what you ask: 由于您已使用PHPMailer对此进行了标记,因此我将展示如何使用它来完成您所要求的操作:

$mail->setFrom('me@example.com', 'Contact form');
$mail->addReplyTo($_POST['email'], $_POST['name']);

This is exactly what the example contact form script provided with PHPMailer does. 这正是PHPMailer提供的示例联系表单脚本所做的。 It's also worth checking submitted values - addReplyTo will validate the address automatically, so you should check the return value to be sure. 还值得检查提交的值addReplyTo将自动验证地址,因此您应该检查返回值以确保。

There may be some email clients that do not handle reply-to addresses correctly, but you should not expose yourself to being blacklisted because of the ineptitude of a small number of clients. 可能有些电子邮件客户端无法正确处理回复地址,但是由于少数客户端的无效性,您不应将自己暴露在黑名单中。

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

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