【发布时间】:2015-12-24 00:47:21
【问题描述】:
我正在尝试发送电子邮件并为此使用 mailtrap。我试图发送的电子邮件只是一个简单的消息,让我们说,“您已收到电子邮件!”但我似乎无法使用 laravel 4.2 来实现,这是我的 mail.php
return array(
'driver' => 'smtp',
'host' => 'mailtrap.io',
'port' => 2525,
'from' => array('address' => 'example@gmail.com', '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() 方法所以我像这样使用它
然后当我尝试它时,我得到一个错误提示
调用未定义的方法 Illuminate\Mail\Mailer::raw()
这是处理它的控制器(我在这里省略了其他功能)
<?php
class POrder extends \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('sample@gmail.com', 'Laravel');
$message->to('sample1@gmail.com')->cc('sample2@yahoo.com');
});
} else {
return Redirect::to('purchase_order')
->withErrors('CAPTCHA code does not match')
->withInput(Input::except('password'));
}
}
}
}
关于我可能做错了什么的任何想法?或者我怎样才能让它工作?谢谢
【问题讨论】:
-
处理这个问题的控制器是什么样的?
-
我将其添加到问题中。谢谢
-
我不是 Laravel 4.2 的专家,但您确定 Mail::raw() 在该版本中受支持吗?查看文档,它只在 Laravel 5.0 及更高版本中出现,laravel.com/docs/4.2/mail
-
哦,是的。我的错。我现在遇到了更多问题,哈哈 :)
-
添加了一个使用
Mail::send()代替Mail::raw()的示例。
标签: php email laravel laravel-4