> 백엔드 개발 > PHP 튜토리얼 > [麦先生]在Laravel框架里实现邮箱验证---发送邮件,laravel---_PHP教程

[麦先生]在Laravel框架里实现邮箱验证---发送邮件,laravel---_PHP教程

WBOY
풀어 주다: 2016-07-12 08:51:46
원래의
1466명이 탐색했습니다.

[麦先生]在Laravel框架里实现邮箱验证---发送邮件,laravel---

      在经过一段时间的使用后,发现在项目中很多地方需要用到用户验证,以短信验证和邮箱验证为主流趋势,小麦总结了如果在Laravel框架中实现发送邮件功能,以后会陆续更上如何实现短信验证.....  

      

      

在.env文件下

 1.配置Laravel文件

     MAIL_DRIVER=smtp  //建议使用smtp方式

     MAIL_HOST=smtp.163.com  //建议使用163邮箱 QQ邮箱会有报错

     MAIL_PORT=25        //smtp 默认为25   

     MAIL_USERNAME=null   //自己的163帐号

     MAIL_PASSWORD=null //客户端密码

     MAIL_ENCRYPTION=null

.

2.修改config/email.php文件中的 

            'from' => ['address' => null, 'name' => null],   //手册上未提示,但实际应用中  如果为addredd=>null则报错,需要天写自己的163地址

 

3. 注册163的邮箱并进行邮箱帐号设置  POP3/SMTP/IMAP都要开启   并开启授权码并进行手机验证

        

 

4.参照Laravel手册里的邮件发送

                必须注意的是  在控制器引用邮件发送时  必须首先引用use  Mail

    ​    ​    ​    ​发送邮件测试

    ​    ​    ​    ​在路由里设置 

      

    ​    ​    ​    ​在控制器中写入方法

                

    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​其中

    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​1:Mail::raw  是发送原生数据,其他的内容发送方式在手册里都有提供;

    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​2.$message->subjuet('');是文件的标题

    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​3.$message->to();发送给谁

    ​    ​    ​

这是一份在 $message 消息生成器实例中可以使用的方法清单:

<code class=" language-php"><span class="token variable">$message<span class="token operator">-<span class="token operator">><span class="token function">from<span class="token punctuation">(<span class="token variable">$address<span class="token punctuation">, <span class="token variable">$name <span class="token operator">= <span class="token keyword">null<span class="token punctuation">)<span class="token punctuation">;
<span class="token variable">$message<span class="token operator">-<span class="token operator">><span class="token function">sender<span class="token punctuation">(<span class="token variable">$address<span class="token punctuation">, <span class="token variable">$name <span class="token operator">= <span class="token keyword">null<span class="token punctuation">)<span class="token punctuation">;
<span class="token variable">$message<span class="token operator">-<span class="token operator">><span class="token function">to<span class="token punctuation">(<span class="token variable">$address<span class="token punctuation">, <span class="token variable">$name <span class="token operator">= <span class="token keyword">null<span class="token punctuation">)<span class="token punctuation">;
<span class="token variable">$message<span class="token operator">-<span class="token operator">><span class="token function">cc<span class="token punctuation">(<span class="token variable">$address<span class="token punctuation">, <span class="token variable">$name <span class="token operator">= <span class="token keyword">null<span class="token punctuation">)<span class="token punctuation">;
<span class="token variable">$message<span class="token operator">-<span class="token operator">><span class="token function">bcc<span class="token punctuation">(<span class="token variable">$address<span class="token punctuation">, <span class="token variable">$name <span class="token operator">= <span class="token keyword">null<span class="token punctuation">)<span class="token punctuation">;
<span class="token variable">$message<span class="token operator">-<span class="token operator">><span class="token function">replyTo<span class="token punctuation">(<span class="token variable">$address<span class="token punctuation">, <span class="token variable">$name <span class="token operator">= <span class="token keyword">null<span class="token punctuation">)<span class="token punctuation">;
<span class="token variable">$message<span class="token operator">-<span class="token operator">><span class="token function">subject<span class="token punctuation">(<span class="token variable">$subject<span class="token punctuation">)<span class="token punctuation">;
<span class="token variable">$message<span class="token operator">-<span class="token operator">><span class="token function">priority<span class="token punctuation">(<span class="token variable">$level<span class="token punctuation">)<span class="token punctuation">;
<span class="token variable">$message<span class="token operator">-<span class="token operator">><span class="token function">attach<span class="token punctuation">(<span class="token variable">$pathToFile<span class="token punctuation">, <span class="token keyword">array <span class="token variable">$options <span class="token operator">= <span class="token punctuation">[<span class="token punctuation">]<span class="token punctuation">)<span class="token punctuation">;
<span class="token comment">
// 以原始 $data 字符串附加一个文件...
<span class="token variable">$message<span class="token operator">-<span class="token operator">><span class="token function">attachData<span class="token punctuation">(<span class="token variable">$data<span class="token punctuation">, <span class="token variable">$name<span class="token punctuation">, <span class="token keyword">array <span class="token variable">$options <span class="token operator">= <span class="token punctuation">[<span class="token punctuation">]<span class="token punctuation">)<span class="token punctuation">;
<span class="token comment">
// 获取底层的 SwiftMailer 消息实例...
<span class="token variable">$message<span class="token operator">-<span class="token operator">><span class="token function">getSwiftMessage<span class="token punctuation">(<span class="token punctuation">)<span class="token punctuation">;</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code>
로그인 후 복사

​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​

    ​    ​    ​    ​    ​ 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1128120.htmlTechArticle[麦先生]在Laravel框架里实现邮箱验证---发送邮件,laravel--- 在经过一段时间的使用后,发现在项目中很多地方需要用到用户验证,以短信验证和...
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿