laravel框架中Email邮件配置

1.在composer.json加入下面一行代码
"guzzlehttp/guzzle""~4.0"
2.发送邮件的Route
Route::get('/mail',['as'=>'emails.index','uses'=>'EmailController@index']);
3.项目/app/mail.php
<?php
return array(
    'driver' => 'smtp',
    'host' => 'smtp.163.com',
    'port' => 25, 或 'port'=>994,
    'from' => array('address' => 'admin@163.com''name' => 'admin'),
    'encryption' => 'tls', 或 'encryption' => 'ssl'/*ssl 和端口994配用 */
    'username' => 'admin@163.com',
    'password' => 'password',
    'sendmail' => '/usr/sbin/sendmail -bs',
    'pretend' => false,
);
4.发送邮件的类
在控制器文件夹下创建EmailController.php
<?php
public function index()
    {
        //$data = ['name'=>'wlian'];
        $data = array(
            'name'  => 'admin',
            'tell'  => '10086',
            'mail'  => 'admin@163.com'
            );
            Mail::send('emails.index',$data,function($message){
                $message->to('qhorse@163.com','wlian')->subject('hello word!!');
                $message->attach(public_path().'/img/banner1.jpg');
            });
        return '已发送';
        return View::make('emails.index')->with('data',$data);
    };
5.显示调用数据的视图
emails/index.blade.php
<p>{{ $name }}</p>
<p>{{ $mail }}</p>
<p>{{ $tell }}</p>
原文地址:https://www.cnblogs.com/qhorse/p/4701132.html