邮件():SMTP服务器响应:503此邮件服务器在尝试发送到非本地电子邮件地址时需要进行身份验证

时间:2022-10-23 15:42:47

Just recently and by accident, I found out that I cannot send emails to foreign sources beyond my server (I've been testing it with local Email addresses being installed at the same server). This is my code and I cannot send to (e.g.) gmail or yahoo.

就在最近,我意外地发现,除了我的服务器之外,我不能向国外源发送电子邮件(我一直在用安装在同一服务器上的本地电子邮件地址测试它)。这是我的代码,我不能发送(例如)gmail或yahoo。

$receiver = $emailadr;
$subj     = 'Auth';
$msg      = 'Thank you!';
$header = 'From: sometestmail@somedomain.com' . "\r\n" . 
'Reply-To: sometestmail@somedomain.com' . "\r\n" . 
'X-Mailer: PHP/' . phpversion() . "\r\n" . 'Content-type: text/html; charset=iso-8859-1';
mail($receiver, $subj, $msg, $header);

When (attempting) sending, it comes up with this:

当(尝试)发送时,会出现以下情况:

: mail(): SMTP server response: 503 This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server.

: mail(): SMTP服务器响应:503此邮件服务器在尝试发送到非本地电子邮件地址时需要进行身份验证。请检查您的邮件客户端设置或联系您的管理员,以验证此服务器的域或地址是否已定义。

I'm using Plesk 12.5

我使用Plesk 12.5

2 个解决方案

#1


3  

Error message is quite clear This mail server requires authentication

错误消息非常清楚,此邮件服务器需要身份验证。

You can create mail user in Plesk and use following PHP class to send mail with authentication:

您可以在Plesk中创建邮件用户,并使用以下PHP类通过身份验证发送邮件:

http://phpmailer.worxware.com/index.php?pg=tutorial#2

http://phpmailer.worxware.com/index.php?pg=tutorial # 2

Also you can try some cloud mail services like http://sendgrid.com/ they have nice PHP API library.

您还可以尝试一些云邮件服务,如http://sendgrid.com/,它们有很好的PHP API库。

#2


0  

Looks like a problem of the mailserver. Your codes is on a shared hosting? Your provided probably has an anti-spam configuration (hopefully). You have to make sure that your sender address is existing. For testing, it's also helpful if you send the message to yourself (if you didn't already), this has more chances to work and then you can check the mail headers.

看起来是邮件服务器的问题。您的代码在共享主机上吗?您提供的可能具有反垃圾邮件配置(希望如此)。您必须确保您的发件人地址是存在的。对于测试,如果您将消息发送给您自己(如果您还没有发送),这也很有帮助,这将有更多的机会工作,然后您可以检查邮件标题。

On a average configured e-mail server, there are four ways of mail communication: (i assume your server is running somedomain.com and is providing @somedomain.com mails)

在一个平均配置的电子邮件服务器上,有四种邮件通信方式:(我假设您的服务器正在运行somedomain.com并提供@somedomain.com邮件)

  • Incoming: Mails from not-@somedomain.com to @somedomain.com. These mails are normally simply accepted.
  • 收到:从not-@somedomain.com发邮件到@somedomain.com。这些邮件通常只被接受。
  • Outgoing: Mails from @somedomain.com to not-@somedomain.com. There mails are accepted if the origin IP address is in the local network (or the webserver). That's what you want
  • 发送:从@somedomain.com发邮件到not-@somedomain.com。如果源IP地址在本地网络(或web服务器)中,则可以接受这些邮件。这就是你想要的
  • Internal: Mails from @somedomain.com to @somedomain.com. That's another option for you, if you send the message to yourself. Here you have the highest change that the mail arrives
  • 内部:邮件从@somedomain.com到@somedomain.com。这是你的另一个选择,如果你自己发送消息。这是你收到的最大的零钱
  • Relay: Mails from not-@somedomain.com to not-@somedomain.com. This is what your server thinks you are doing. Relaying mails is normally denied except for authenticated users because it's normally spam (and that's what it tells you in the error message). Unfortunately, the standard PHP sendmail function doesn't support authentication. Because of this, you need to add the sender address to the mailserver's whitelist or (easier:) change it to an accepted internal address which changes your mail to an outgoing or internal one, depending on the receiver address.
  • 中继:从not-@somedomain.com发邮件到not-@somedomain.com。这是您的服务器认为您正在做的事情。中继邮件通常被拒绝,除非是经过身份验证的用户,因为它通常是垃圾邮件(这是它在错误消息中告诉你的)。不幸的是,标准的PHP sendmail函数不支持身份验证。因此,您需要将发送方地址添加到mailserver的白名单中,或者(更容易:)将其更改为一个已接受的内部地址,这将根据接收者地址将您的邮件更改为传出或内部地址。

#1


3  

Error message is quite clear This mail server requires authentication

错误消息非常清楚,此邮件服务器需要身份验证。

You can create mail user in Plesk and use following PHP class to send mail with authentication:

您可以在Plesk中创建邮件用户,并使用以下PHP类通过身份验证发送邮件:

http://phpmailer.worxware.com/index.php?pg=tutorial#2

http://phpmailer.worxware.com/index.php?pg=tutorial # 2

Also you can try some cloud mail services like http://sendgrid.com/ they have nice PHP API library.

您还可以尝试一些云邮件服务,如http://sendgrid.com/,它们有很好的PHP API库。

#2


0  

Looks like a problem of the mailserver. Your codes is on a shared hosting? Your provided probably has an anti-spam configuration (hopefully). You have to make sure that your sender address is existing. For testing, it's also helpful if you send the message to yourself (if you didn't already), this has more chances to work and then you can check the mail headers.

看起来是邮件服务器的问题。您的代码在共享主机上吗?您提供的可能具有反垃圾邮件配置(希望如此)。您必须确保您的发件人地址是存在的。对于测试,如果您将消息发送给您自己(如果您还没有发送),这也很有帮助,这将有更多的机会工作,然后您可以检查邮件标题。

On a average configured e-mail server, there are four ways of mail communication: (i assume your server is running somedomain.com and is providing @somedomain.com mails)

在一个平均配置的电子邮件服务器上,有四种邮件通信方式:(我假设您的服务器正在运行somedomain.com并提供@somedomain.com邮件)

  • Incoming: Mails from not-@somedomain.com to @somedomain.com. These mails are normally simply accepted.
  • 收到:从not-@somedomain.com发邮件到@somedomain.com。这些邮件通常只被接受。
  • Outgoing: Mails from @somedomain.com to not-@somedomain.com. There mails are accepted if the origin IP address is in the local network (or the webserver). That's what you want
  • 发送:从@somedomain.com发邮件到not-@somedomain.com。如果源IP地址在本地网络(或web服务器)中,则可以接受这些邮件。这就是你想要的
  • Internal: Mails from @somedomain.com to @somedomain.com. That's another option for you, if you send the message to yourself. Here you have the highest change that the mail arrives
  • 内部:邮件从@somedomain.com到@somedomain.com。这是你的另一个选择,如果你自己发送消息。这是你收到的最大的零钱
  • Relay: Mails from not-@somedomain.com to not-@somedomain.com. This is what your server thinks you are doing. Relaying mails is normally denied except for authenticated users because it's normally spam (and that's what it tells you in the error message). Unfortunately, the standard PHP sendmail function doesn't support authentication. Because of this, you need to add the sender address to the mailserver's whitelist or (easier:) change it to an accepted internal address which changes your mail to an outgoing or internal one, depending on the receiver address.
  • 中继:从not-@somedomain.com发邮件到not-@somedomain.com。这是您的服务器认为您正在做的事情。中继邮件通常被拒绝,除非是经过身份验证的用户,因为它通常是垃圾邮件(这是它在错误消息中告诉你的)。不幸的是,标准的PHP sendmail函数不支持身份验证。因此,您需要将发送方地址添加到mailserver的白名单中,或者(更容易:)将其更改为一个已接受的内部地址,这将根据接收者地址将您的邮件更改为传出或内部地址。