在Laravel中已经有内置了发送邮件的功能,通过 Mail::send 可发送邮件,但要使用这个函数必须先进行相关配置。

  在 /app/config/mail.php 中设置你的邮件参数,如下:

   1 <?php
2 return array(
3
4 /*
5 |--------------------------------------------------------------------------
6 | Mail Driver
7 |--------------------------------------------------------------------------
8 |
9 | Laravel supports both SMTP and PHP's "mail" function as drivers for the
10 | sending of e-mail. You may specify which one you're using throughout
11 | your application here. By default, Laravel is setup for SMTP mail.
12 |
13 | Supported: "smtp", "mail", "sendmail", "mailgun", "mandrill", "log"
14 |
15 */
16
17 'driver' => 'smtp',
18
19 /*
20 |--------------------------------------------------------------------------
21 | SMTP Host Address
22 |--------------------------------------------------------------------------
23 |
24 | Here you may provide the host address of the SMTP server used by your
25 | applications. A default option is provided that is compatible with
26 | the Mailgun mail service which will provide reliable deliveries.
27 |
28 */
29
30 'host' => 'smtp.163.com',
31
32 /*
33 |--------------------------------------------------------------------------
34 | SMTP Host Port
35 |--------------------------------------------------------------------------
36 |
37 | This is the SMTP port used by your application to deliver e-mails to
38 | users of the application. Like the host we have set this value to
39 | stay compatible with the Mailgun e-mail application by default.
40 |
41 */
42
43 'port' => 25,
44
45 /*
46 |--------------------------------------------------------------------------
47 | Global "From" Address
48 |--------------------------------------------------------------------------
49 |
50 | You may wish for all e-mails sent by your application to be sent from
51 | the same address. Here, you may specify a name and address that is
52 | used globally for all e-mails that are sent by your application.
53 |
54 */
55
56 'from' => array (
57 'address' => 'xxx@163.com',
58 'name' => 'xxx@163.com'
59 ),
60
61 /*
62 |--------------------------------------------------------------------------
63 | E-Mail Encryption Protocol
64 |--------------------------------------------------------------------------
65 |
66 | Here you may specify the encryption protocol that should be used when
67 | the application send e-mail messages. A sensible default using the
68 | transport layer security protocol should provide great security.
69 |
70 */
71
72 'encryption' => 'tls',
73
74 /*
75 |--------------------------------------------------------------------------
76 | SMTP Server Username
77 |--------------------------------------------------------------------------
78 |
79 | If your SMTP server requires a username for authentication, you should
80 | set it here. This will get used to authenticate with your server on
81 | connection. You may also set the "password" value below this one.
82 |
83 */
84
85 'username' => 'xxx@163.com',
86
87 /*
88 |--------------------------------------------------------------------------
89 | SMTP Server Password
90 |--------------------------------------------------------------------------
91 |
92 | Here you may set the password required by your SMTP server to send out
93 | messages from your application. This will be given to the server on
94 | connection so that the application will be able to send messages.
95 |
96 */
97
98 'password' => 'xxx',
99
100 /*
101 |--------------------------------------------------------------------------
102 | Sendmail System Path
103 |--------------------------------------------------------------------------
104 |
105 | When using the "sendmail" driver to send e-mails, we will need to know
106 | the path to where Sendmail lives on this server. A default path has
107 | been provided here, which will work well on most of your systems.
108 |
109 */
110
111 'sendmail' => '/usr/sbin/sendmail -bs',
112
113 /*
114 |--------------------------------------------------------------------------
115 | Mail "Pretend"
116 |--------------------------------------------------------------------------
117 |
118 | When this option is enabled, e-mail will not actually be sent over the
119 | web and will instead be written to your application's logs files so
120 | you may inspect the message. This is great for local development.
121 |
122 */
123
124 'pretend' => false
125 );

  其中的 driver、host、port 和 encryption 等自己可以根据相应邮件服务器的属性来设置。

  在 Mail::send 中,需要注意其中的参数,如下:

 if (!$this->postUsernameCheck() && !$this->postEmailCheck())
{
$pwd = User::where('username', Input::get('username'))->where('email', Input::get('email'))->get();
$msg = Input::get('username') . " , your password is : " . Hash::make($pwd[0]->password);
$messageData = array('msgnext' => $msg);
$emails = 'Passdd'; Mail::send('emails.view', $messageData, function ($message) use ($pwd,$emails) {
$message->to($pwd[0]->email);
$message->subject($emails);
}); return Redirect::to('main')->with('user' , Input::get('username'));
}
else
return Redirect::back();

  send 的第一个参数是view的页面,你可以在view文件夹里添加blade文件,输入相应的代码来显示的数据,我的页面是 {{ $msgnext }};

  第二个参数是一维数组,不可是其他多维的;

  第三个参数是匿名函数,变量名不可与第二个参数一样,可用 use 来连接函数外部的变量。

  这样你的邮件就想发就发了!

Laravel邮件发送问题小解的更多相关文章

  1. laravel邮件发送

    laravel邮件发送 使用邮件发送类Mail 文本 静态方法 raw() 富文本 静态方法 send() 注:使用邮件发送必须有邮件账号,需要开启smtp协议,现在主流服务器都支持,smtp默认端口 ...

  2. Laravel - 上手实现 - 邮件发送

    Laravel 自带 SwiftMailer 库,集成了多种邮件API,可以很方便的实现邮件的发送. 我们使用到的是SMTP(Simple Message Transfer Protocol)简单邮件 ...

  3. Laravel5.5 邮件驱动使用 SMTP 驱动实现邮件发送

    laravel5.5 邮件驱动 Laravel 支持多种邮件驱动,包括 smtp.Mailgun.Maildrill.Amazon SES.mail 和 sendmail.Mailgun . Mail ...

  4. .NET开发邮件发送功能的全面教程(含邮件组件源码)

    今天,给大家分享的是如何在.NET平台中开发“邮件发送”功能.在网上搜的到的各种资料一般都介绍的比较简单,那今天我想比较细的整理介绍下: 1)         邮件基础理论知识 2)         ...

  5. J2EE 邮件发送那些事儿

    距离自己写的关于java邮件发送的第一篇博客已经有很长一段时间了,现在回过头看看.虽然代码质量方面有待提高,整体结构也不怎样,但是基本思路和过程还是比较纯的.现在有空写写J2EE中邮件发送的开发,实际 ...

  6. 结合ABP源码实现邮件发送功能

    1. 前言 2. 实现过程 1. 代码图(重) 2.具体实现 2.1 定义AppSettingNames及AppSettingProvider 2.2 EmailSenderConfiguration ...

  7. SSH项目里面 忘记密码的邮件发送功能

    package com.xxx.util; import java.util.Date; import java.util.Properties; import javax.mail.Address; ...

  8. [UWP]UWP中获取联系人/邮件发送/SMS消息发送操作

    这篇博客将介绍如何在UWP程序中获取联系人/邮件发送/SMS发送的基础操作. 1. 获取联系人 UWP中联系人获取需要引入Windows.ApplicationModel.Contacts名称空间. ...

  9. java spring 邮件发送

    开发中经常会遇到发送邮件进行用户验证,或者其它推送信息的情况,本文基于spring,完成邮件的发送,主要支持普通文本邮件的发送,html文本邮件的发送,带附件的邮件发送,没有实现群发.多个附件发送等需 ...

随机推荐

  1. Notes over compiling..

    When compiling VIM on windows, using nmake may be a better choice.. Because so far my attempts to co ...

  2. aX+bY+cZ=n(非负整数解存在性)

    题意: a*1234567+b*123456+c*1234=n 非负整数解得存在性. 题解: 看代码. #include<iostream> #include<cstdio> ...

  3. HDU 2489 Minimal Ratio Tree (DFS枚举+最小生成树Prim)

    Minimal Ratio Tree Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) ...

  4. 转:全面剖析C#正则表达式

    到目前为止,许多的编程语言和工具都包含对正则表达式的支持,当然.NET也不例外,.NET基础类库中包含有一个名称空间和一系列可以充分发挥规则表达式威力的类.         正则表达式的知识可能是不少 ...

  5. maven实战_测试覆盖率插件使用

    原文:http://www.cnblogs.com/yucongblog/p/5297051.html 1.环境准备 <project> ... <reporting> < ...

  6. 使用print2flash开发在线文档

    www.print2flash.com 命令行调用: A:\Program Files (x86)\Print2Flash3>p2fServer.exe a.pdf a.swf

  7. vr & obv

    买卖信号 1.当VR曲线的运行形态一底比一底低,而OBV曲线的运行形态一底比一底高,同时股价也突破中短期均线,则表明VR指标和OBV出现了底背离走势,这是VR指标发出的短线买入信号.如图(15–1)所 ...

  8. BASE64-客户端(js)加码-服务器端(c#)解码,URL传递“汉字参数”解决方法

    HttpUtility.UrlEncode 在 Encode 的时候, 将空格转换成加号('+'), 在 Decode 的时候将加号转为空格, 但是浏览器是不能理解加号为空格的, 所以如果文件名包含了 ...

  9. 开发板S3C2440挂起NFS步骤

    第一.安装.配置.启动FTP.SSH或NFS服务 参考韦东山的嵌入式linux应用开发完全手册 http://pan.baidu.com/s/1o79h3n0 第二.windows.linux以及开发 ...

  10. CodeForces 158C - Cd and pwd commands(模拟)

    这个题我们又把题意理解错了,队友翻译了以后给我解释,我问这个直接一个单词开头的是要找到这个文件夹吗,他说是,然后我就呵呵了..奔着树形结构去和字符串维护就去了...做了好久都没模拟出来,感觉做出来的人 ...