使用提供程序时的Laravel邮件配置

时间:2015-10-08 19:47:37

标签: php laravel laravel-5

我想做一个发送邮件的助手,我首先是为我的助手做提供者和自定义课程。

  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, ]'

  4. 问题是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

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

1 个答案:

答案 0 :(得分:2)

看起来你把配置放在了错误的地方。

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

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