【问题标题】:sending email in localhost via laravel 4.2 using gmail mail driver使用 gmail 邮件驱动程序通过 laravel 4.2 在 localhost 中发送电子邮件
【发布时间】:2015-12-23 05:27:31
【问题描述】:

我尝试使用 laravel 4 发送电子邮件并使用 gmail 邮件驱动程序,我已经将我的 config/mail.phpfile 更改为如下内容:

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

提前致谢

【问题讨论】:

    标签: php email laravel laravel-4


    【解决方案1】:

    您需要添加一个映射到控制器的路由:

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

    然后将您的验证和邮件功能添加到doStuff 方法中。

    【讨论】:

      【解决方案2】:

      view 是用于电子邮件正文的模板。

      http://laravel.com/docs/4.2/mail 提供有关如何操作的更多信息。

      您的视图文件可能如下所示:

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

      【讨论】:

        猜你喜欢
        • 2018-03-21
        • 1970-01-01
        • 2017-07-16
        • 2012-03-22
        • 2012-01-07
        • 2023-03-19
        • 2018-01-09
        相关资源
        最近更新 更多