我尝试使用laravel 4发送电子邮件并使用gmail邮件驱动程序我已经将config/mail.php
文件更改为以下内容:
return array(
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => array('address' => 'email_that_im_using', 'name' => 'Trial'),
'encryption' => 'ssl',
'username' => 'mygmailusername',
'password' => 'mygmailpassword',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
这是我在控制器中的代码
Mail::send('view', $data, function($message)
{
$message->to(Input::get('SupplierEmail') , 'Jon Doe')->subject('Sample Mail!');
});
我很遗憾我会把这些观点放在'部分和$ data部分是我的视图
这是我视图中的表单代码
{{ Form::open(array('url' => 'addpurchorder')) }}
<div class="form-group">
{{ Form::label('module', 'Select Module: ') }}
{{ Form::select('ModuleInfo', [null=>'Please Select Module'] + $modules , Input::old('ModuleInfo'), array('class'=>'form-control'))}}
</div>
<div class="form-group">
{{ Form::label('qty', 'Quantity') }}
{{ Form::text('Quantity', Input::old('Quantity'), array('class' => 'form-control','placeholder' => 'Enter Quantity')) }}
</div>
<div class="form-group">
<h4><i><span class="label label-success">NOTE: Default Status is pending</span></i></h4>
</div>
<div class="form-group">
{{ Form::label('from', 'School Email (From)') }}
{{ Form::text('SchoolEmail', Input::old('SchoolEmail'), array('class' => 'form-control','placeholder' => 'Enter School Email')) }}
</div>
<div class="form-group">
{{ Form::label('to', 'Supplier Email (To)') }}
{{ Form::text('SupplierEmail', Input::old('SupplierEmail'), array('class' => 'form-control','placeholder' => 'Enter Supplier Email')) }}
</div>
<div class="form-group">
{{ Form::label('captcha', 'CAPTCHA image: ') }}
</br>
{{ HTML::image('http://localhost:8080/laravel3/app/captcha.php', 'alt' , array( 'width' => 250, 'height' => 43 )) }} </br></br>
{{ Form::text('capt', Input::old('capt'), array('class' => 'form-control','placeholder' => 'enter generated captcha')) }}
</div>
{{ Form::submit('Create Purchase Order', array('class' => 'btn btn-primary')) }}
{{ Form::close()}}
提前致谢
答案 0 :(得分:1)
view
是用于电子邮件正文的模板。
http://laravel.com/docs/4.2/mail提供了有关如何操作的更多信息。
您的视图文件可能如下所示:
<body>
Hello {{ $data->name }}
</body>
答案 1 :(得分:1)
您需要添加映射到控制器的路线:
Route::post('addpurchorder', 'PurchaseController@doStuff');
然后将您的验证和邮件程序功能添加到doStuff
方法中。