版权声明:本文为博主原创文章,未经博主允许不得转载。 https://cloud.tencent.com/developer/article/1333687
POP3/SMTP/IMAP
”进行下面的设置,着重记下服务器地址(SMTP 服务器:smtp.163.com)config/mail.php
'from' => ['address' => '1xxxxxxx@163.com', 'name' => '逗比2号'],
MAIL_DRIVER=smtp
MAIL_HOST=smtp.163.com
MAIL_PORT=25
MAIL_USERNAME=1xxxxxxx@163.com
MAIL_PASSWORD=xxxxx
MAIL_ENCRYPTION=null
Route::any('mail', 'TestController@mail');
<?php
namespace App\Http\Controllers;
use Illuminate\Mail\Mailer;
class TestController extends Controller
{
private $mailer;
public function __construct(Mailer $mailer)
{
$this->mailer = $mailer;
}
/**
* 发送邮件
*/
public function mail(){
//测试数据
$viewData = ['title' => '你若盛开,清风自来','author' => '木心'];
$emailData = [
'content' => '从前的日色变得慢 车 马 邮件 都慢',
'subject' => '这是邮件主题,希望您能支持!',//邮件主题
'addr' => 'xxxxxxxxx@qq.com',//邮件接收地址
];
$this->sendText($emailData);
//$this->sendHtml('mail',$viewData,$emailData);
//TODO $tag 判断发送是否成功,进行后续代码开发
return view('mail',['title' => '你若盛开,清风自来','author' => '木心']);
}
/**
* 发送纯文本 邮件
* @param $emailData 邮件数据
*/
public function sendText($emailData){
//此处为文本内容
$tag = $this->mailer
->raw($emailData['content'],
function ($message)use ($emailData){
$message->subject($emailData['subject']);
$message->to($emailData['addr']);
});
return $tag;
}
/**
* 发送自定义网页
* @param $emailData 邮件数据
* @param $viewPage html视图
* @param $viewData html传输数据
*/
public function sendHtml($viewPage,$viewData,$emailData){
$tag = $this->mailer
->send($viewPage,$viewData,
function ($message) use ($emailData){
$message->subject($emailData['subject']);
$message->to($emailData['addr']);
});
return $tag;
}
}
mail.blade.php
参考代码如下:<html>
<style>
*{
font-family: 楷体;
}
</style>
<h2>{{$title}}</h2>
![]({{asset('uploads/20170902/59aa05723e35d.jpg')}})
<pre>
从前的日色
变得慢
车 马 邮件
都慢
一生只够爱一个人
--{{$author}}
</pre>
</html>
use Illuminate\Support\Facades\Mail;
$tag = Mail::raw('你好,我们已经准备好了',function ($message){
$message->to('9xxxxxxxxxx@qq.com');
});
FatalErrorException
in ClassLoader.php line 373:Maximum function nesting level of '100' reached, aborting!
{{ csrf_field() }}