我試圖發送電子郵件和即時消息使用mailtrap爲此。我試圖發送的電子郵件只是一個普通的垃圾郵件讓我們說,「你已通過電子郵件發送!」但我似乎無法使用laravel 4.2在這裏是我的mail.php
使用laravel 4.2和mailtrap發送簡單的消息到電子郵件
return array(
'driver' => 'smtp',
'host' => 'mailtrap.io',
'port' => 2525,
'from' => array('address' => '[email protected]', 'name' => 'SSIMS'),
'encryption' => 'ssl',
'username' => 'sadasdadsadadsad', //not my real username
'password' => '341ssfsdf2342', //not my real password
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
只是複製這個從mailtrap.io
的話,我不知道如何使用laravel發送電子郵件進行。事情是即時消息不發送任何意見,我只是想發送一些簡單的消息,所以在4.2的文檔中,我看到有這個Mail::raw()
方法,所以我用它這樣的
然後當我嘗試它,我得到一個錯誤說
電話未定義的方法照亮\郵件\郵遞員::原始()
這裏是處理它的控制器(ⅰ省略了其他功能在這裏)
<?php
類POrder什麼我可能做錯了擴展\ {BaseController
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
//
$title = "Purchase Order Page";
$modules = prchorder::lists('ModuleName','ModuleID');
return View::make('ssims.purchaseorder_index',compact('title','modules'));
}
public function chkInput()
{
session_start();
$getsCapt = $_SESSION["captcha"];
$rules = array(
'ModuleInfo' => 'required',
'Quantity' => 'required|numeric|digits_between:2,5',
'SchoolEmail' => 'required|min:10|max:254|email',
'SupplierEmail' => 'required|min:10|max:254|email',
'capt' => 'required|numeric'
);
$messages = array(
'ModuleInfo.required' => 'Please Select a Module.',
//'SchoolEmail.email' => 'Please Enter a Valid Email for the School Email.',
//'SupplierEmail.email' => 'Please Enter a Valid Email for the Supplier Email.',
'capt.numeric' => 'CAPTCHA code must be a number.',
'SchoolEmail.same' => 'School Email cannot be same with the Supplier Email.',
'SupplierEmail.same' => 'Supplier Email cannot be same with the School Email.',
);
$validator = Validator::make(Input::all(), $rules, $messages);
$uCapt = Input::get('capt');
// process the inputs given by the user
if ($validator->fails())
{
return Redirect::to('purchase_order')
->withErrors($validator)
->withInput(Input::except('password'));
}
else
{
if($uCapt == $getsCapt)
{
$sEmail = Input::get('SupplierEmail');
//return Redirect::to('purchase_order');
Mail::raw('Text to e-mail', function($message)
{
$message->from('[email protected]', 'Laravel');
$message->to('[email protected]')->cc('[email protected]');
});
}
else
{
return Redirect::to('purchase_order')
->withErrors('CAPTCHA code does not match')
->withInput(Input::except('password'));
}
}
}
}
任何想法?或者我如何使它工作?感謝
你的控制器是如何處理的? – James
我將它添加到問題中。謝謝 – BourneShady
我不是Laravel 4.2的專家,但是您確定該版本支持Mail :: raw()嗎?查看文檔,它只在Laravel 5.0及更高版本中成爲一件事,http://laravel.com/docs/4.2/mail – James