繁体   English   中英

在使用Laravel发送之前如何编辑电子邮件正文

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM