Laravel 电子邮件未发送但没有错误,使用自己的 smtp 服务器

Laravel email not sended but no error, with own smtp server

我有一个 SMTP 服务器随托管服务器一起提供,已经正确使用了主机、端口、用户名、密码等。电子邮件正在发送,但 returns 没有错误。它在邮件陷阱中工作。我使用 beautymail 发送电子邮件。根据我的 cpanel 站点配置是正确的。

我的.env

MAIL_DRIVER=smtp
MAIL_MAILER=smtp
MAIL_HOST=mail.(myweb).com
MAIL_PORT=465
MAIL_USERNAME=cs@(myweb).com
MAIL_PASSWORD=(mypass)
MAIL_FROM_ADDRESS=no-reply@(myweb).com
MAIL_FROM_NAME=(myname)
MAIL_ENCRYPTION=ssl

我的 mail.php 文件(可能有用?)

<?php

return [

/*
|--------------------------------------------------------------------------
| Default Mailer
|--------------------------------------------------------------------------
|
| This option controls the default mailer that is used to send any email
| messages sent by your application. Alternative mailers may be setup
| and used as needed; however, this mailer will be used by default.
|
*/

'default' => env('MAIL_MAILER', 'smtp'),

/*
|--------------------------------------------------------------------------
| Mailer Configurations
|--------------------------------------------------------------------------
|
| Here you may configure all of the mailers used by your application plus
| their respective settings. Several examples have been configured for
| you and you are free to add your own as your application requires.
|
| Laravel supports a variety of mail "transport" drivers to be used while
| sending an e-mail. You will specify which one you are using for your
| mailers below. You are free to add additional mailers as required.
|
| Supported: "smtp", "sendmail", "mailgun", "ses",
|            "postmark", "log", "array"
|
*/

'mailers' => [
    'smtp' => [
        'transport' => 'smtp',
        'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
        'port' => env('MAIL_PORT', 587),
        'encryption' => env('MAIL_ENCRYPTION', null),
        'username' => env('MAIL_USERNAME'),
        'password' => env('MAIL_PASSWORD'),
        'timeout' => null,
    ],

    'ses' => [
        'transport' => 'ses',
    ],

    'mailgun' => [
        'transport' => 'mailgun',
    ],

    'postmark' => [
        'transport' => 'postmark',
    ],

    'sendmail' => [
        'transport' => 'sendmail',
        'path' => '/usr/sbin/sendmail -bs',
    ],

    'log' => [
        'transport' => 'log',
        'channel' => env('MAIL_LOG_CHANNEL'),
    ],

    'array' => [
        'transport' => 'array',
    ],
],

/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/

'from' => [
    'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
    'name' => env('MAIL_FROM_NAME', 'Example'),
],

/*
|--------------------------------------------------------------------------
| Markdown Mail Settings
|--------------------------------------------------------------------------
|
| If you are using Markdown based email rendering, you may configure your
| theme and component paths here, allowing you to customize the design
| of the emails. Or, you may simply stick with the Laravel defaults!
|
*/

'markdown' => [
    'theme' => 'default',

    'paths' => [
        resource_path('views/vendor/mail'),
    ],
],

];

一直在四处寻找,但没有对我有用,谢谢...

发件服务器 (SMTP):mail.(myweb).com 端口:465

编辑:附加信息,当我在 outlook 中手动设置电子邮件时一切正常。电子邮件已发送,收件箱正常工作。下面的一些信息可能有用

Username:   cs@(myweb).com
Password:   Use the email account’s password.
Incoming Server:    mail.(myweb).com
IMAP Port: 993 POP3 Port: 995

Outgoing Server:    mail.(myweb).com
SMTP Port: 465

如果您使用的是安全邮件设置,请试试这个

MAIL_DRIVER=smtp
MAIL_HOST=mail.(myweb).com //MAIL_HOST=myweb.com
MAIL_PORT=465
MAIL_USERNAME=cs@(myweb).com
MAIL_PASSWORD=(mypass)
MAIL_ENCRYPTION=ssl

不要忘记在 .env

中进行更改后清除配置缓存 config:clear

如果您的安全设置只有外发邮件服务器 myweb.com 那么您的 MAIL_HOST 将变为 MAIL_HOST=myewb.com 您的其余设置没问题,但也请确保在收件箱中等待 10 到 15 分钟收到的邮件。

已解决!

在与我的托管支持长时间讨论后,主要问题是我在发送电子邮件时使用了不同的电子邮件地址。电子邮件地址应该与 SMTP 用户名相同 (cs@myweb.com)

之前

Route::get('/test', function()
{
    $beautymail = app()->make(Snowfire\Beautymail\Beautymail::class);
    $beautymail->send('email.welcome', [], function($message)
    {
        $message
            ->from('bar@example.com')
            ->to('emailto@gmail.com', 'Customer Test')
            ->subject('Welcome!');
    });

});

Route::get('/test', function()
{
    $beautymail = app()->make(Snowfire\Beautymail\Beautymail::class);
    $beautymail->send('email.welcome', [], function($message)
    {
        $message
            ->from('cs@myweb.com')
            ->to('emailto@gmail.com', 'Customer Test')
            ->subject('Welcome!');
    });

});

.env中的SMTP设置可以参考@Akhtar Munir的回答

谢谢大家的回复。欣赏一下。