0
在我的應用程序的管理面板中,我構建了一個簡單的表單,用於發送簡報。 只有兩個字段:SUBJECT - BODY。Laravel 4:通過表格發送郵件
我想要的點擊發送,郵件將被髮送到通訊的所有訂閱用戶(現在也只是用戶::第一個(),以測試它)
,但我得到這個錯誤:查看[郵件正文]未找到。
我想問:可以發送簡單的郵件,只有文本,或者我必須發送一個視圖作爲郵件正文?
如果是有用的,這是我的梅勒類:
<?php namespace Mailers;
class InvalidContactInfoException extends \Exception {}
abstract class Mailer {
public $to;
public $email;
public $subject;
public $view;
public $data;
public $options;
public function __construct($user)
{
if(!is_object($user))
{
throw new InvalidContactInfoException('Please pass a valid user object');
}
$this->data = $user->toArray();
$this->to = $user->username;
$this->email = $user->email;
}
public function deliver()
{
$self = $this;
return \Mail::send($this->body, $this->data, function($message) use($self)
{
$message->to($self->email, $self->to)->subject($self->subject);
});
}
}
這是Usermailer類:
<?php namespace Mailers;
class UserMailer extends Mailer {
public function newsletter($subject, $body)
{
$this->subject = $subject;
$this->body = $body;
return $this;
}
}
而且控制器方法:
public function sendNewsletter()
{
$input = Input::all();
$rules = array('subject' => 'required', 'body' => 'required');
$validation = Validator::make($input, $rules);
if($validation->passes())
{
$subject = $input['subject'];
$body = $input ['body'];
$user = User::first();
$mailer = new Mailers\UserMailer($user);
$mailer->newsletter($subject,$body)->deliver();
return Redirect::back()->with('message','Congratulations, the newsletter has been sent succesfully');
}
return Redirect::back()->withInput()->withErrors($validation)->with('message','There were validation errors');
}
過程o f發送它的郵件工作正常...因爲如果在身體例如我寫'主'然後在我的電子郵件中,我收到一封電子郵件:作爲主題插入的形式和身體主視圖主題....
所以這個問題只是關於我想發送純文本而不是視圖的事實。
有人可以幫助我嗎? 謝謝!