2015-09-26 103 views
1

我試圖發送電子郵件和即時消息使用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')); 
     } 

    } 
} 

}

任何想法?或者我如何使它工作?感謝

+1

你的控制器是如何處理的? – James

+0

我將它添加到問題中。謝謝 – BourneShady

+1

我不是Laravel 4.2的專家,但是您確定該版本支持Mail :: raw()嗎?查看文檔,它只在Laravel 5.0及更高版本中成爲一件事,http://laravel.com/docs/4.2/mail – James

回答

1

由於Laravel 4.2不支持Mail::raw(),只需用Mail::send()替換它,像這樣:

Mail::send('emails.example', array('a_value' => 'you_could_pass_through'), function($message) 
{ 
    $message->to('[email protected]', 'John Smith')->cc('[email protected]')->subject('Example!'); 
}); 

在這個例子中,emails.example指稱爲在電子郵件例子視圖與其餘文件夾觀點。 array('a_value' => 'you_could_pass_through')就是這樣一個數組,它傳遞數據以查看。如果您沒有要傳入的數據,則只需使用array(),因爲它是Mail::send()的必需部分。

其餘的只是設置to和cc字段,from信息已經來自您設置的mail.php文件。

+0

如果在我的'emails.example'我的視圖中出現了一些問題。說'不支持的操作數類型'這裏是我的視圖中的表單9 – BourneShady

+1

您應該爲此創建一個問題並提供您正在使用的導致錯誤的代碼。 – James

+0

好的,非常感謝! – BourneShady

相關問題