Laravel 使用 smtp 服务器发送自定义电子邮件地址时出错

Laravel error when sending custom email address using smtp server

我有一个项目有一个模块可以根据请求发送电子邮件。我使用 beautymail 包作为电子邮件模板。我可以使用 gmail 帐户发送电子邮件,但是我从客户那里收到的这封电子邮件中有一个客户电子邮件地址。像这样xx.xxxxx@propnex.sg,他们说邮件是smtp服务器。所以我尝试在 laravel 中配置我的 .env 和其他配置文件。但是我在发送 Connection could not be established with host mail.propnex.sg :stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:1408F10B:SSL routines:ssl3_get_record:wrong version number 时收到此错误有人可以告诉我为什么我收到此错误以及我应该怎么做才能摆脱它?非常感谢

.env 配置

MAIL_DRIVER=smtp
MAIL_HOST=mail.propnex.sg
MAIL_PORT=587
MAIL_USERNAME=xx.xxxxx@propnex.sg
MAIL_PASSWORD=xxxxxxxx
MAIL_ENCRYPTION=ssl

Mail.php

   'from' => [
        'address' => 'xx.xxxxx@propnex.sg',
        'name' => 'Propnex',
    ],

    'reply_to' => ['address' => 'xx.xxxxx@propnex.sg', 'name' => 'Propnex'],

    'encryption' => env('MAIL_ENCRYPTION', 'tls'),


    'username' => env('MAIL_USERNAME'),

    'password' => env('MAIL_PASSWORD'),

    'port' => env('MAIL_PORT', 587),

    'driver' => env('MAIL_DRIVER', 'smtp'),

    'host' => env('MAIL_HOST', 'mail.propnex.sg'),

我只是通过在我的 .env 和 mail.php 文件中做一些小改动解决了这个问题

MAIL_ENCRYPTION=""
'encryption' => env('MAIL_ENCRYPTION', ''),

告诉我这个 unsecured/alternative 答案的缺点是什么。我想要反馈。非常感谢。

You are setting mail encryption as tls in mail.php and on the other hand in the env file
you are setting it to ssl. Try setting it the same in both the files.

But i would recommend that you skip the certificate.
You can skip verification of the ssl certificate by using the code below in the mail.php file:

 'stream' => [
        'ssl' => [
            'allow_self_signed' => true,
            'verify_peer' => false,
            'verify_peer_name' => false,
        ],
    ],

您正在使用 SSL (MAIL_ENCRYPTION=ssl),因此您需要在 .env 文件中更改 MAIL_PORT=465。

您可能已经越过检查了您拥有的每一行。问题在于 mailtrap.io 它本身。如果你的配置真的是下面这样

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=31466861b7bXXX
MAIL_PASSWORD=fe2b6503618XXX
MAIL_ENCRYPTION=null

我测试了两个独立的框架来证明这个错误。检查 SMTP 凭据尝试重置凭据。

SSL VS TLS 加密

TLS 使用端口:587 对于 SSL 使用端口:465