简体   繁体   English

使用gmail邮件驱动程序通过laravel 4.2在本地主机中发送电子邮件

[英]sending email in localhost via laravel 4.2 using gmail mail driver

im trying to send an email using laravel 4 and using the gmail mail driver i've already changed my config/mail.php file into something like this: 我试图使用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,

); );

and here is my code inside the controller 这是我控制器内的代码

Mail::send('view', $data, function($message) 
            {
                $message->to(Input::get('SupplierEmail') , 'Jon Doe')->subject('Sample Mail!');
            });

im kinda lost on what will i put on the 'view' part and the $data part here is what my view looks like 我有点迷失了我将在“视图”部分放的内容,这里的$ data部分是我的视图的样子 我的观点

and here is the code of my form inside my view 这是我视图中表单的代码

{{ 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()}}

thanks in advance 提前致谢

The view is the template that is be used for the email's body. view是用于电子邮件正文的模板。

http://laravel.com/docs/4.2/mail gives more information about how to do it. http://laravel.com/docs/4.2/mail提供了有关如何执行此操作的更多信息。

your view file can look like this: 您的视图文件如下所示:

<body>
    Hello {{ $data->name }}
</body>

You need to add a route that maps to a controller: 您需要添加映射到控制器的路由:

Route::post('addpurchorder', 'PurchaseController@doStuff');

Then add your validation, and mailer function above to the doStuff method. 然后将您的验证和上面的mailer函数添加到doStuff方法中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM