【问题标题】:Laravel mail configuration if using providersLaravel 邮件配置(如果使用提供者)
【发布时间】:2015-10-08 19:47:37
【问题描述】:

我想做一个发送邮件的助手,我是从为我的助手做提供者和自定义类开始的。

  1. 我的提供者注册功能:

    public function register()
    {
        $this->app->bind('mailer.helper', function (Application $app){
            return new MailerHelper($app->make('mailer'));
        });
    }
    
  2. 我的辅助函数:

    class MailerHelper implements SelfHandling{
    
    /** @var Mailer $mailer */
    protected $mailer;
    
    public function __construct(Mailer $mailer) {
        $this->mailer=$mailer;
    }
    
    
    public function sendFromContact(array $date){
    
        $this->mailer->send('email_templates/contact', $date, function (Message $message){
            $message->setTo('stroia.laurentiu92@gmail.com');
            $message->setFrom('contact@dianabotezan.ro','Contact website Diana Botezan');
            $message->setSubject('Forumlar contact');
        });
    }
    }
    
  3. 我的配置来自 config/mail.php:

    return [ 'driver' => env('MAIL_DRIVER', 'smtp'), 'host' => env('MAIL_HOST', 'smtp.gmail.com'), 'port' => env('MAIL_PORT', 587), 'from' => ['address' => null, 'name' => null], 'encryption' => env('MAIL_ENCRYPTION', 'ssl'), 'username' => env('my_gmal@gmail.com'), 'password' => env('mypassword'), 'sendmail' => '/usr/sbin/sendmail -bs', 'pretend' => false, ]'

问题是 laravel 的配置不好,这是我尝试做的事情:

Connection could not be established with host 127.0.0.1 [Connection refused #111]

1. in StreamBuffer.php line 265 2. at Swift_Transport_StreamBuffer->_establishSocketConnection() in StreamBuffer.php line 62 3. at Swift_Transport_StreamBuffer->initialize(array('protocol' => null, 'host' => '127.0.0.1', 'port' => '2525', 'timeout' => '30', 'blocking' => '1', 'tls' => false, 'type' => '1')) in AbstractSmtpTransport.php line 113

在这里你可以观察到他有其他配置然后我设置它。我做错了什么?

【问题讨论】:

    标签: php laravel laravel-5


    【解决方案1】:

    您的配置似乎放错了位置。

    您应该将邮件配置设置放在项目根目录下的.env 文件中,而不是直接编辑config/mail.php 文件。

    你可以see here in the sample file shipped with laravel

    【讨论】:

    • 谢谢!但你能说它是什么 config/mail.php 吗?
    • config/mail.php 只需使用 env 帮助器在您的 .env 文件中提取信息。
    猜你喜欢
    • 2015-07-25
    • 2011-03-05
    • 2016-12-08
    • 2013-08-29
    • 1970-01-01
    • 2013-03-11
    • 1970-01-01
    • 2015-10-18
    • 1970-01-01
    相关资源
    最近更新 更多