Php 如何在使用Laravel发送前编辑电子邮件正文
我已经生成了电子邮件功能,可以使用laravel向多人发送电子邮件 现在我想生成一个编辑窗口,这样我就可以编写电子邮件的正文,就像在Gmail中一样,如果我们发送邮件,我们首先编辑正文,然后点击发送邮件Php 如何在使用Laravel发送前编辑电子邮件正文,php,email,laravel-5,smtp,Php,Email,Laravel 5,Smtp,我已经生成了电子邮件功能,可以使用laravel向多人发送电子邮件 现在我想生成一个编辑窗口,这样我就可以编写电子邮件的正文,就像在Gmail中一样,如果我们发送邮件,我们首先编辑正文,然后点击发送邮件 因此,如果有人知道我如何实现这一点,请留下评论。尽管我本人对拉雷维尔来说是个新手,但我可以尝试帮助您解决这一问题。首先,在routes.php文件中设置路由。例如 Route::get('myapp/sendEmail', 'EmailController@returnComposeEmail'
因此,如果有人知道我如何实现这一点,请留下评论。尽管我本人对拉雷维尔来说是个新手,但我可以尝试帮助您解决这一问题。首先,在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');
});
}
您可以按原样或根据需要使用电子邮件/body.blade.php
文件中的$dataArray
如果我能帮忙,一定要告诉我。:-) 虽然我本人对拉威尔还不太熟悉,但我可以试着帮你解决这个问题。首先,在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');
});
}
您可以按原样或根据需要使用电子邮件/body.blade.php
文件中的$dataArray
如果我能帮忙,一定要告诉我。:-) 应该尽可能简单
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');
});
它应该尽可能简单
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');
});
控制器:
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');
查看联系人电子邮件包含要发送的数据,查看电子邮件我们正在通过邮件功能发送。当用户将数据放入表单中时,由于以下代码行,该数据将保存在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);
控制器:
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');
查看联系人电子邮件包含要发送的数据,查看电子邮件我们正在通过邮件功能发送。当用户将数据放入表单中时,由于以下代码行,该数据将保存在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);
我不知道如何在laravel中实现它,但我会给你留下一条评论,告诉你你的问题太广泛了。用两个输入文本制作一个表单。第一个输入应该是电子邮件主题,第二个输入应该是电子邮件正文。然后,在“点击”按钮“发送”之后,您实际上将数据从控制器发送给这些人。我不知道如何在laravel中实现它,但我会给你留下一条评论,告诉你你的问题太广泛了。用两个输入文本制作一个表单。第一个输入应该是电子邮件主题,第二个输入应该是电子邮件正文。然后,在“点击”按钮“发送”之后,您实际上将数据从控制器发送给这些人。我就是这么做的。。