[英]how to edit email body before sending using Laravel
我已經生成了電子郵件功能,可以使用laravel將電子郵件發送給多個人。
現在,我想生成一個編輯窗口,以便我可以像在Gmail中那樣編寫電子郵件的正文,如果我們要發送郵件,我們首先要編輯正文,然后單擊“發送郵件”。
因此,如果有人知道我該如何實施,請發表評論。
它應該像
Mail::send([], array('yourValue' => $yourValue), function($message) use ($yourValue) {
$MailBody = 'Your Custom Body';
$message->setBody($MailBody, 'text/html');
$message->to('yourtoaddress@yourdomain.com');
$message->subject('Your Custom Subject');
});
盡管我自己對Laravel並不陌生,但我可以嘗試幫助您。 首先,在Routes.php文件中設置您的路線。 例如
Route::get('myapp/sendEmail', 'EmailController@returnComposeEmail');
Route::post('myapp/sendEmail', 'EmailController@sendEmail');
訪問時的第一條路線應將視圖返回給用戶,以便用戶撰寫電子郵件。 這基本上是一種表單,當用戶單擊“發送”按鈕時將由POST
方法提交。 第二種途徑是該方法,該方法將收集提交的數據並適當地使用它然后發送電子郵件。
如果按照我提供的路線進行操作,則應該使用以下方法創建一個名為EmailController.php
的控制器文件:
public function returnComposeEmail()
{
return view('pages.ComposeEmail');
}
public function sendEmail(Request $input)
{
$input = $input->all();
$dataArray = array();
$dataArray['emailBody'] = $input['emailBody'];
$to = $input['to'];
$subject = $input['subject'];
Mail::send('email.body', ['dataArray' => $dataArray], function ($instance) use ($to, $subject)
{
$instance->from(env('MAIL_USERNAME'), 'Your Name Here');
$instance->to($to, 'Recipient Name');
$instance->subject($subject);
$instance->replyTo(env('MAIL_REPLY_TO', 'some@email.id'), 'Desired Name');
});
}
您可以按原樣或根據需要使用email/body.blade.php
文件中的$dataArray
。
讓我知道我是否可以幫忙。 :-)
控制器:
public function showForm(Request $request )
{
//Get Content From The Form
$name = $request->input('name');
$email = Input::get('agree');
$message = $request->input('message');
//Make a Data Array
$data = array(
'name' => $name,
'email' => $email,
'message' => $message
);
//Convert the view into a string
$emailView = View::make('contactemail')->with('data', $data);
$contents = (string) $emailView;
//Store the content on a file with .blad.php extension in the view/email folder
$myfile = fopen("../resources/views/emails/email.blade.php", "w") or die("Unable to open file!");
fwrite($myfile, $contents);
fclose($myfile);
//Use the create file as view for Mail function and send the email
Mail::send('emails.email', $data, function($message) use ($data) {
$message->to( $data['email'], 'Engage')->from('stifan@xyz.com')->subject('A Very Warm Welcome');
});
// return view();
}
路線:
Route::post('contactform', 'ClientsController@showForm');
Route::get('/', 'ClientsController@profile');
視圖contactemail具有要發送的數據,以及我們正在通過郵件功能發送的視圖電子郵件 。 當用戶將數據放入表單時,由於以下幾行代碼,該數據將保存在email.blade.php中:
//Convert the view into a string
$emailView = View::make('contactemail')->with('data', $data);
$contents = (string) $emailView;
//Store the content on a file with .blad.php extension in the view/email folder
$myfile = fopen("../resources/views/emails/email.blade.php", "w") or die("Unable to open file!");
fwrite($myfile, $contents);
fclose($myfile);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.