预期响应代码为220,但在laravel 5.6中得到空响应

时间:2019-03-11 06:53:48

标签: laravel laravel-5.6

我在laravel 5.6中使用mailgun发送电子邮件,但返回错误(预期响应代码为220,但响应为空)。以下是我的所有文件设置。

.env文件

MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME = postmaster@domainname 
MAIL_PASSWORD = password
MAILGUN_DOMAIN = domainname 
MAILGUN_SECRET = key
MAIL_ENCRYPTION=tls

mail.php文件

<?php

return [

     'mailgun' => [
        'domain' => env('MAILGUN_DOMAIN'),
        'secret' => env('MAILGUN_SECRET'),
    ],
    'ses' => [
        'key' => env('SES_KEY'),
        'secret' => env('SES_SECRET'),
        'region' => 'us-east-1',
    ],
    'sparkpost' => [
        'secret' => env('SPARKPOST_SECRET'),
    ],
    'stripe' => [
        'model' => App\User::class,
        'key' => env('STRIPE_KEY'),
        'secret' => env('STRIPE_SECRET'),
    ],
];

services.php文件

<?php

return [
    'driver' => env('MAIL_DRIVER', 'mailgun'),
    'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
    'port' => env('MAIL_PORT', 587),
    'from' => ['address' => 'aakanskhi.cuminte@gmail.com', 'name' => 'Aakankshi Gupta'],
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),
    'username' => env('postmaster@domain'),
    'password' => env('mailgun password'),
    'sendmail' => '/usr/sbin/sendmail -bs',
    'markdown' => [
        'theme' => 'default',
        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],
];

public function testmail(){
$user = User::findOrFail(8);
Mail::send('emails.test',  ['user' => $user], function ($message) {
$message->from('us@example.com', 'Laravel');
$message->to('aakankshi.cuminte@gmail.com')->subject('Your Reminder!');;
});
}

运行代码时,它会显示以下错误消息:

Swift_TransportException 期望的响应代码为220,但响应为空

如何解决此错误消息?

2 个答案:

答案 0 :(得分:0)

只需在终端上运行以下代码:

public static void saveList(String saveName, ArrayList<Book> books) throws IOException {
        FileOutputStream fos = new FileOutputStream(saveName);
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(books);
        oos.close();
    }

public static ArrayList<Book> loadList(String saveName) throws ClassNotFoundException, IOException {
    FileInputStream fis = new FileInputStream(saveName);
    ObjectInputStream ois = new ObjectInputStream(fis);
    ArrayList<Book> books = (ArrayList<Book>) ois.readObject();
    ois.close();
    return books;
}

答案 1 :(得分:0)

仅对于Mailgun,您只需在.env文件中指定以下字段即可。

MAIL_DRIVER = mailgun

MAILGUN_DOMAIN = XY.mailgun.org

MAILGUN_SECRET = key-XYZ