简体   繁体   English

当我在 laravel 中发送邮件时发送 Html 标签

[英]Html tags are sent when i am sending mail in laravel

I am using the tiny editor and i want to send an email with formatting without HTML tags but it sends HTML tags.我正在使用微型编辑器,我想发送一个 email 格式没有 HTML 标签,但它发送 HTML 标签。 I am using laravel.我正在使用 laravel。 I am giving below how my mail comes.我在下面给出我的邮件是如何来的。 and what I have to do to send mail to multiple recipients.以及如何将邮件发送给多个收件人。 Please help me to make it run successfully.请帮助我使其成功运行。
Controller:- Controller:-

\Mail::send('emails.contact',
array(                 
'email' => $request->get('email'),                 
'sub' => $request->get('sub'),
'bodyMessage' => $request->get('message'),
), function($message) use ($request)
{
$message->from('harsha1604gandhi@gmail.com');
$message->to($request->get('email'));
$message->subject($request->sub);
});

View:-看法:-

<form class="form-horizontal" action="contact" method="post">
{{csrf_field()}}
<div class="form-group">
<label class="control-label col-sm-2" for="email">To:</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" placeholder="Enter email" name="email" multiple>
<a id="bccemail" style="float: right;padding-left:5px;">Bcc</a>
<a id="ccemail" style="float: right;">Cc</a>        
</div>
</div>
<div class="form-group" id="divcc" style="display: none;">
<label class="control-label col-sm-2"></label>
<div class="col-sm-10">
<input type="email" class="form-control" id="emailcc" placeholder="Cc" name="emailcc">       
</div>
</div>
<div class="form-group" id="divbcc" style="display: none;">
<label class="control-label col-sm-2"></label>
<div class="col-sm-10">
<input type="email" class="form-control" id="emailbcc" placeholder="Bcc" name="emailbcc">       
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="pwd">Subject:</label>
<div class="col-sm-10">          
<input type="text" class="form-control" id="sub" placeholder="Enter Subject" name="sub">
</div>
</div>
<div class="form-group">        
<div class="col-sm-offset-2 col-sm-10">
<div class="">
<textarea name="message" id="msg"></textarea>
</div>
</div>
</div>
<div class="form-group">        
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Send</button>
</div>
</div>
</form>
</div>

<script>                    
tinymce.init({
selector: '#msg',
plugins: 'code link image media paste anchor quickbars'
});
$(document).ready(function(){
$("#ccemail").click(function(){
$("#divcc").toggle();
});
$("#bccemail").click(function(){
$("#divbcc").toggle();
});
});
</script>
</html>

Mail:- Here my screenshot of mail邮件:-这是我的邮件截图

You didn't show your email template view, but I imagine that you are using blade {{ }} statement to output the message to it.您没有显示您的 email 模板视图,但我想您正在使用刀片{{ }}语句向 output 发送消息。

But, accordingly to Laravel Docs:但是,根据 Laravel 文档:

Blade {{ }} statements are automatically sent through PHP's htmlspecialchars function to prevent XSS attacks. Blade {{ }}语句通过 PHP 的htmlspecialchars function 自动发送,以防止 XSS 攻击。

and

If you do not want your data to be escaped, you may use the following syntax:如果您不希望您的数据被转义,您可以使用以下语法:

. . Hello, {.!你好, {。! $name !!}. $名称!!}。

So you must replace the {{ }} by {!! !}}因此,您必须将{{ }}替换为{!! !}} {!! !}} where you output the message containing html code. {!! !}}你 output 包含 html 代码的消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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