开发者

How to mail the content from a tinymce texteditor in PHP?

开发者 https://www.devze.com 2023-02-18 18:34 出处:网络
I need a mail function in my php project. I am using tinymce text editor to type the mail body content. My mail function working well. But the content from the text editor display <p>Mail body C

I need a mail function in my php project. I am using tinymce text editor to type the mail body content. My mail function working well. But the content from the text editor display <p>Mail body Content</p> (including tags). I need to display only the content.

Below is my code

$charset='UTF-8';
$subject=$_REQUEST['mail_subject'];
开发者_Python百科$mail_to=$_REQUEST['mail_to'];
$body=$_REQUEST['mail_body'];
$name=ucfirst($user_firstName)." ".ucfirst($user_lastName);
$encoded_subject="=?$charset?B?".base64_encode($subject)."?=\n";
$mailBody="";
$mailBody="Dear ".$name.",\n";
$mailBody.=$body;

$headers="From: My site Name\n"
. "Content-Type: text/plain; charset=$charset; format=flowed\n"
. "MIME-Version: 1.0\n"
. "Content-Transfer-Encoding: 8bit\n"
. "X-Mailer: PHP\n";

$mailResult=mail($mail_to,$encoded_subject, $mailBody,$headers);


You are using Content-type: text/plain.

To send HTML email, you need to change the content type, eg:

$headers  = 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";


I recommend you to use the Swift mailer library, here I found a nice tutorial: Swift tutorial

You should set the content type to text/html as you can see on this page: Setting the Character Set - Swift Mailer


By using a html editor the result is in html code. So i suppose all you want to do is to get rid of the editor content tags.

This can be done using the strip_tags php function.

$editor_content = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags( $editor_content );
0

精彩评论

暂无评论...
验证码 换一张
取 消