Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 邮件未通过Mailgun API Laravel 8发送_Php_Laravel_Mailgun - Fatal编程技术网

Php 邮件未通过Mailgun API Laravel 8发送

Php 邮件未通过Mailgun API Laravel 8发送,php,laravel,mailgun,Php,Laravel,Mailgun,我试图通过mailgun API从我的控制器发送邮件,但是邮件没有到达mailgun,并且我没有收到任何错误消息/日志 这在我的.env中: MAIL_MAILER=mailgun MAILGUN_DOMAIN=subdomain.domain.ca MAILGUN_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxx MAIL_MAILER=mailgun MAIL_HOST=smtp.mailgun.org MAIL_PORT=2525 MAIL_USERNAME=null

我试图通过mailgun API从我的控制器发送邮件,但是邮件没有到达mailgun,并且我没有收到任何错误消息/日志

这在我的
.env
中:

MAIL_MAILER=mailgun
MAILGUN_DOMAIN=subdomain.domain.ca
MAILGUN_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxx
MAIL_MAILER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_NAME=YourNameHere
MAIL_FROM_ADDRESS=enter@theemail.com
MAIL_FROM=enter@theemail.com
MAILGUN_DOMAIN=subdomain.domain.ca
MAILGUN_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxx
这在我的
services.php
中:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Third Party Services
    |--------------------------------------------------------------------------
    |
    | This file is for storing the credentials for third-party services such
    | as Mailgun, Postmark, AWS, and more. This file provides the de facto
    | location for this type of information, allowing packages to have
    | a conventional file to locate the various service credentials.
    |
    */

    'mailgun' => [
        'domain' => env('subdomain.domain.ca'),
        'secret' => env('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'),
    ],

    'postmark' => [
        'token' => env('POSTMARK_TOKEN'),
    ],

    'ses' => [
        'key' => env('AWS_ACCESS_KEY_ID'),
        'secret' => env('AWS_SECRET_ACCESS_KEY'),
        'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
    ],

];
<?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', 'mailgun'),

    /*
    |--------------------------------------------------------------------------
    | 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', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => null,
            'auth_mode' => 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', 'info@domain.ca'),
        'name' => env('MAIL_FROM_NAME', 'From name'),
    ],

    /*
    |--------------------------------------------------------------------------
    | 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'),
        ],
    ],

];
以下是我在控制器中发送邮件的方式:

Mail::send('emailtemplates.trackeremail', $data, function($message)use($data, $pdf) {
                $message->to($data["toaddress"])
                        ->cc($data["ccaddress"])
                        ->subject($data["title"])
                        ->attachData($pdf->output(), "PDFName.pdf");
            });
当我在本地环境中通过SMTP向mailgun发送邮件时,这是有效的,但不幸的是,我仅限于不允许第三方SMTP的共享主机,我需要切换到API方法进行生产。我已经在这个网站(和其他网站)上浏览了很多相关的教程和问题,但是没有任何东西解决我的问题

在任何类型的
.env
更改之后,我都会运行
php-artisan-config:clear


我还能做些什么来获取错误消息或进一步调试它吗?任何帮助都将不胜感激。

可能是来自以下地址的端口、主机、加密和邮件:

保持这些内容在
.env
中的原样:

MAIL_MAILER=mailgun
MAILGUN_DOMAIN=subdomain.domain.ca
MAILGUN_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxx
MAIL_MAILER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_NAME=YourNameHere
MAIL_FROM_ADDRESS=enter@theemail.com
MAIL_FROM=enter@theemail.com
MAILGUN_DOMAIN=subdomain.domain.ca
MAILGUN_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxx
.env
中输入这些:

MAIL_MAILER=mailgun
MAILGUN_DOMAIN=subdomain.domain.ca
MAILGUN_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxx
MAIL_MAILER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_NAME=YourNameHere
MAIL_FROM_ADDRESS=enter@theemail.com
MAIL_FROM=enter@theemail.com
MAILGUN_DOMAIN=subdomain.domain.ca
MAILGUN_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxx
使用以下内容更新
services.php

    'mailgun' => [
        'domain'   => env('MAILGUN_DOMAIN'),
        'secret'   => env('MAILGUN_SECRET'),
        'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
    ],
更新
mail.php
,添加:

'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'port' => env('MAIL_PORT', 587),

在与A2 Hosting的技术支持讨论了这一点之后,发现这在他们的共享托管中是不可能的,我被告知“Mailgun只支持标准SMTP端口,因此在我们的共享服务器上不受支持”。

只是为了确保我清楚-您提到的那些“保持原样”,你的意思是在
mail.php
文件中吗?以及您在
.env
中列出的“输入这些”值,对吗?将添加内容添加到
mail.php
services.php
中,然后保持上述内容“不变”
.env
插件与您的
.env
文件中上面列出的插件相同。我做了上面列出的更改,但不幸的是仍然发生了同样的事情。代码正在运行,但没有邮件发送到mailgun,我没有收到任何错误。