【问题标题】:Laravel: All RCPT commands were rejected with this error: 503-relay not permitted, authentication requiredLaravel:所有 RCPT 命令都被拒绝并出现此错误:503-relay not allowed, authentication required
【发布时间】:2019-03-12 18:25:25
【问题描述】:

我用 Laravel 创建了一个网站,它使用电子邮件通知用户某些事情。为了在我的个人电脑上进行测试,我使用我的 gmail 帐户从 te 网站发送电子邮件,效果非常好。现在我想向公众发布该网站,对于最终版本,我希望它使用 noreply@mydomain 发送电子邮件而不是我的 gmail 地址。

因此,我在.env 文件中设置了环境变量,如下所示:

MAIL_DRIVER=smtp
MAIL_HOST=mail1.webyte.eu
MAIL_PORT=587
MAIL_USERNAME=noreply@mydomain
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls

我的托管服务人员告诉我这应该是正确的,但是,当我尝试这样做时,我收到以下错误:

Swift_TransportException (503) 预期响应代码 354 但得到代码 “503”,带有消息“503-All RCPT commands were denied with this 错误:503-relay not allowed, authentication required 503 Valid RCPT 命令必须在 DATA 之前”

我已经在互联网上搜索了几天,找不到任何适合我的东西......

有人知道我应该在这里做什么吗?谢谢!

【问题讨论】:

    标签: laravel email laravel-5


    【解决方案1】:

    此错误是由您的 SMTP 电子邮件服务提供商引发的。 Laravel 使用 SwiftMailer 发送电子邮件。所以你可以使用下面的方法来捕捉错误

    try {
      Mail::send('emails.contact-message', [
       'msg' => $request->body,
       'name' => $request->name,
       'email' => $request->email,
    
      ],
    
         function ($mail) use($request) {
           $mail->from($request->email, $request->name);
           $mail->to('support@domain.com')->subject('Contact Message');
         }
    
       );
     // Catch the error
     } catch(\Swift_TransportException $e){
        if($e->getMessage()) {
           dd($e->getMessage());
        }             
     }
    

    【讨论】:

      【解决方案2】:

      我还通过在我的 .env 文件中包含以下内容来修复此错误:

      MAIL_DRIVER=sendmail
      

      【讨论】:

        【解决方案3】:

        我通过改变想通了:

        MAIL_DRIVER=发送邮件

        【讨论】:

        • 感谢您的回答,但是我无法验证它,因为我使用了一种完全不同的方法来使网站正常运行。我希望这可能对其他人有所帮助,因为我真的遇到了很大的麻烦......
        【解决方案4】:

        有些服务器有特殊设置。例如,对于我在 namecheap 上的服务器,我需要在 .env 文件中添加这些变量

        MAIL_FROM_ADDRESS=noreply@mydomain

        MAIL_FROM_NAME=NoReply

        【讨论】:

          猜你喜欢
          • 2021-11-11
          • 2016-07-25
          • 2020-02-03
          • 2018-12-30
          • 1970-01-01
          • 2015-12-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多