Van*_*an6 8 php email laravel laravel-5
好吧,让我首先开始说我对laravel 5很新.我一直在google上搜索只是通过输入相应的URL而没有运气来发送一封简单的电子邮件.不幸的是,我发现那里的文档并没有那么有用,只是给出了一个广泛的外观(我理解laravel 5是新的,但仍然令人沮丧哈哈).对于我正在尝试做的事情没有任何幻想,我只是想在我做其他任何事情之前将其付诸实践.我现在正试图使用gmail来解决这个问题,但是一旦我解决了这个问题,我当然会尝试像Mailgun这样的东西.这是我现在的代码第一个是在mail.php中:
return [
/*
|--------------------------------------------------------------------------
| Mail Driver
|--------------------------------------------------------------------------
|
| Laravel supports both SMTP and PHP's "mail" function as drivers for the
| sending of e-mail. You may specify which one you're using throughout
| your application here. By default, Laravel is setup for SMTP mail.
|
| Supported: "smtp", "mail", "sendmail", "mailgun", "mandrill", "log"
|
*/
'driver' => env('smtp'),
/*
|--------------------------------------------------------------------------
| SMTP Host Address
|--------------------------------------------------------------------------
|
| Here you may provide the host address of the SMTP server used by your
| applications. A default option is provided that is compatible with
| the Mailgun mail service which will provide reliable deliveries.
|
*/
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
/*
|--------------------------------------------------------------------------
| SMTP Host Port
|--------------------------------------------------------------------------
|
| This is the SMTP port used by your application to deliver e-mails to
| users of the application. Like the host we have set this value to
| stay compatible with the Mailgun e-mail application by default.
|
*/
'port' => env('MAIL_PORT', 587),
/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/
'from' => ['address' =>"exmaple@gmail.com" , 'name' => "example_name"],
/*
|--------------------------------------------------------------------------
| E-Mail Encryption Protocol
|--------------------------------------------------------------------------
|
| Here you may specify the encryption protocol that should be used when
| the application send e-mail messages. A sensible default using the
| transport layer security protocol should provide great security.
|
*/
'encryption' => 'tls',
/*
|--------------------------------------------------------------------------
| SMTP Server Username
|--------------------------------------------------------------------------
|
| If your SMTP server requires a username for authentication, you should
| set it here. This will get used to authenticate with your server on
| connection. You may also set the "password" value below this one.
|
*/
'username' => env('example@gmail.com'),
/*
|--------------------------------------------------------------------------
| SMTP Server Password
|--------------------------------------------------------------------------
|
| Here you may set the password required by your SMTP server to send out
| messages from your application. This will be given to the server on
| connection so that the application will be able to send messages.
|
*/
'password' => env('example'),
/*
|--------------------------------------------------------------------------
| Sendmail System Path
|--------------------------------------------------------------------------
|
| When using the "sendmail" driver to send e-mails, we will need to know
| the path to where Sendmail lives on this server. A default path has
| been provided here, which will work well on most of your systems.
|
*/
'sendmail' => '/usr/sbin/sendmail -bs',
/*
|--------------------------------------------------------------------------
| Mail "Pretend"
|--------------------------------------------------------------------------
|
| When this option is enabled, e-mail will not actually be sent over the
| web and will instead be written to your application's logs files so
| you may inspect the message. This is great for local development.
|
*/
'pretend' => false,
];
Run Code Online (Sandbox Code Playgroud)
这是我的路线:
Route::get('test', function()
{
Mail::send('Email.test', function ($message)
{
$message->to('example@gmail.com', 'example_name')->subject('Welcome!');
});
});
Run Code Online (Sandbox Code Playgroud)
我也试过了MailController@Sending_Email路径.这是在我的MailController中:
class MailController extends Controller{
public function Sending_Email()
{
$this->call('GET','Email.test');
return View('Email.test');
}
}
Run Code Online (Sandbox Code Playgroud)
我的观点是这个简单的代码:
<html>
<head>
</head>
<body>
<h1>hey this is a test to see if my email system works</h1>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是我的错误:
Missing argument 1 for Illuminate\Support\Manager::createDriver(), called in /vagrant/leonis/vendor/laravel/framework/src/Illuminate/Support/Manager.php on line 89 and defined
你有几个问题正在发生.首先:
'driver' => env('smtp'),
Run Code Online (Sandbox Code Playgroud)
该env方法查看.env文件.我的猜测是你的.env文件中没有"smtp"条目.我只想改变它:
'driver' => 'smtp',
Run Code Online (Sandbox Code Playgroud)
这应该照顾createDriver()错误.
如果您仍然遇到驱动程序问题,或者稍后在向SMTP服务器进行身份验证时遇到问题,请在运行时快速检查配置:
dd(Config::get("mail"));
Run Code Online (Sandbox Code Playgroud)
由于您已env()检查.env设置然后回退到默认值,因此查看生成的配置的外观会很有帮助.
现在你仍然有一个如何打电话的问题Mail::send.这是你的代码:
Mail::send('Email.test', function ($message)
Run Code Online (Sandbox Code Playgroud)
这来自Laravel文档:
Mail::send('emails.welcome', ['key' => 'value'], function($message)
Run Code Online (Sandbox Code Playgroud)
请注意,第二个参数是一个数组.回调函数应该是第三个参数.
来自文档:
第二个是要传递给视图的数据,通常作为关联数组,其中数据项可通过$ key对视图使用.
所以做这样的事情:
Mail::send('Email.test', [], function ($message) {
$message->to('example@gmail.com', 'example_name')->subject('Welcome!');
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21371 次 |
| 最近记录: |