【问题标题】:How to set up a smtp connection on a domain email in laravel如何在 laravel 中的域电子邮件上设置 smtp 连接
【发布时间】:2018-10-17 21:14:46
【问题描述】:

我有一个域:www.mydomain.ro,我创建了一个这样的电子邮件:office@mydomain.ro

我正在尝试从我的 laravel 应用程序(laravel 5.7)发送电子邮件,我做了以下配置:

在 .env 文件中:

    MAIL_DRIVER=smtp
    MAIL_HOST=office@my-domain.ro
    MAIL_PORT=26
    MAIL_USERNAME=office@my-domain.ro
    MAIL_PASSWORD=mypassword
    MAIL_ENCRYPTION=null

在 config/mail.php 中:

<?php

return [

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

    'host' => env('MAIL_HOST', 'mail.my-domain.ro '),

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

    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', 'office@muy-domain.ro'),
        'name' => env('MAIL_FROM_NAME', 'Office my-domain'),
    ],

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

    'username' => env('office@my-domain.ro'),

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

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

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

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

];

在控制器中我正在这样做:

$data = array(
    'name' => 'Ioan Andrei',
    'body' => 'Test Email'
);


Mail::send('emails.demandreceived',$data,function ($message){
    $message->from('office@my-domain.ro','TEST');
    $message->to('ioan.andrei97@gmail.com');
    $message->subject('Test email');

我得到这个错误:

Connection could not be established with host office@msipremiumcars.ro [php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known #0]

我做错了什么?它不起作用,因为我试图从我的本地服务器发送它们?

我可以使用 mailgun 来发送电子邮件,并且仍然从 office@mydomain.ro 发送电子邮件吗?

我尝试在配置后重新启动本地服务器。

Laravel 版本:5.7

【问题讨论】:

    标签: email laravel-5 smtp


    【解决方案1】:

    问题在于.env 文件中的MAIL_HOST。它需要像 my-domain.ro 这样的主机名,而不是您当前输入的电子邮件地址 office@my-domain.ro

    【讨论】:

      猜你喜欢
      • 2016-08-28
      • 2018-06-11
      • 2020-01-13
      • 2014-11-29
      • 1970-01-01
      • 2018-01-01
      • 2013-12-18
      • 2017-02-11
      • 2018-04-09
      相关资源
      最近更新 更多