简体   繁体   English

发送未经身份验证的SMTP电子邮件

[英]Sending SMTP Email without Authentication

My webhost does not allow mail accounts to be created. 我的Web主机不允许创建邮件帐户。 However they have provided me with their SMTP gateway and said no credentials are needed when the mails are being sent from their datacenter. 但是他们为我提供了SMTP网关,并且说从数据中心发送邮件时不需要凭据。

$mail->isSMTP();
$mail->SMTPDebug    = 2;
$mail->Host         = GATEWAY_PROVIDED_BY_HOST
$mail->SMTPAuth     = false;
$mail->SMTPSecure   = false;

Invalid address: (From): root@localhost 无效地址:(发件人):root @ localhost

It seems I need to add a from address. 看来我需要添加一个发件人地址。 But in the case that they do not allow a mail account to be created, what do I put in the from address? 但是,如果他们不允许创建邮件帐户,我应该在发件人地址中输入什么?

Try to use a valid sender "from" email address. 尝试使用“发件人”电子邮件地址的有效发件人。

Update: You have to use a sender address which is the mail server responsible for (or a white listed one). 更新:您必须使用一个发件人地址,该地址是负责的邮件服务器(或白名单中的一个)。 normal "@domain.tld" is enought. 普通的“ @ domain.tld”就足够了。 the name in front of the at is often not tested. at前面的名称通常未经测试。

Also possible: you can only send "to" the domain which is the mail server responsible for or you have to authenticate. 也可能:您只能将“发送到”负责邮件服务器的域,或者您必须进行身份验证。 best is you contact your server provider. 最好是与您的服务器提供商联系。

You need to set a From address: 您需要设置一个发件人地址:

$mail->setFrom('user@example.com', 'My Name');

This will set the from address that appears in message headers, but it will also used as the MAIL FROM command at the SMTP level (where your error is coming from) as it's automatically copied to the Sender PHPMailer property which applies there. 这将设置出现在邮件标题中的MAIL FROM地址,但由于它会自动复制到适用于此的Sender PHPMailer属性,因此它还将在SMTP级别(您的错误出处)用作MAIL FROM命令。 That will avoid the fallback to the root@localhost address you're getting. 这样可以避免回退到您获得的root@localhost地址。

The other things you're doing to disable authentication are correct. 您要禁用身份验证的其他事情是正确的。

Create a Google Account and use it: 创建一个Google帐户并使用它:

$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Username = "your@gmail.com";
$mail->Password = "*****";
$mail->SMTPSecure = "ssl";  
$mail->Host = "smtp.gmail.com";
$mail->Port = "465";
$mail->setFrom('your@gmail.com', 'Your Name');
$mail->addReplyTo('your@gmail.com', 'Your Name');

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

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