Swift_TransportException:LaravelApp无法从共享主机服务器(Hostinger)发送电子邮件

时间:2018-04-04 02:17:43

标签: laravel email

我想从共享托管服务器发送来自larevel app的电子邮件。

以下是.env文件中的配置:

MAIL_DRIVER=smtp
MAIL_HOST=mx1.hostinger.in
MAIL_PORT=587
MAIL_USERNAME=****
MAIL_PASSWORD=****
MAIL_ENCRYPTION=null

我也试过这个:

MAIL_DRIVER=smtp
MAIL_HOST=mx1.hostinger.in
MAIL_PORT=465
MAIL_USERNAME=****
MAIL_PASSWORD=****
MAIL_ENCRYPTION=ssl

还尝试使用 sendmail 驱动程序

MAIL_DRIVER=sendmail
MAIL_HOST=mx1.hostinger.in
MAIL_PORT=465
MAIL_USERNAME=****
MAIL_PASSWORD=****
MAIL_ENCRYPTION=ssl

但是其中任何一个都不起作用,未能发送电子邮件。 请帮助我解决这个问题。

我收到此错误:

enter image description here

以下是我的config/mail.php

<?php

 return [
'driver' => env('MAIL_DRIVER', 'sendmail'),

'host' => env('MAIL_HOST', 'mx1.hostinger.in'),
'port' => env('MAIL_PORT', 465),

'from' => [
    'address' => env('MAIL_FROM_ADDRESS', 'notification@mydomain.com'),
    'name' => env('MAIL_FROM_NAME', ''),
],

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

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

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

'sendmail' => '/usr/sbin/sendmail -bs',



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

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

2 个答案:

答案 0 :(得分:0)

在邮件加密中使用ssl

  1. MAIL_DRIVER = SMTP
  2. MAIL_HOST = mx1.hostinger.in
  3. MAIL_PORT = 587
  4. MAIL_USERNAME = ****
  5. MAIL_PASSWORD = ****
  6. MAIL_ENCRYPTION = SSL
  7. 确保config / mail.php文件中的主机和端口详细信息与.env文件相同。

答案 1 :(得分:0)

我认为您忘记添加“ MAIL_FROM_ADDRESS”和“ MAIL_FROM_NAME”。

这对我有用:

MAIL_DRIVER=smtp
MAIL_HOST=mx1.hostinger.com.br
MAIL_PORT=587
MAIL_USERNAME=yourmail@domain.com.br
MAIL_PASSWORD=******
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=yourmail@domain.com.br
MAIL_FROM_NAME=yourname