0

I am currently working on a php project that connects to imap and insert emails into MySQL. I added UI to reply to the email by which it canned them together. I am having one issue. If I send an email to someone it send all data fine, if the person reply it reinserts everything again. I would like to just insert the person reply and strip out the rest of the message. how can I do this? Any suggestions?

I tried wrapping the entire insert with < section > tag and tried to use preg_replace to ignore all it's content but no luck.

This is what my insert looks like

$message=strip_tags($message, "<br><p><u><span><hr>");
$message=preg_replace("/(<br\ ?\/?>)+/", "<br/>", $message);
$message= preg_replace('/<section[^>]*>([\s\S]*?)<\/section[^>]*>/', '', $message);

$message=clean("<br/><hr><u>Received On $rep_date / $from_email</u><br/>$message");

mysql_query("UPDATE USER SET INFO = CONCAT('$message',INFO) WHERE ID='$id'");

The Data stored in MySQL looks like this

<section> <p>Test data</p> etc </section>

This works but just it reinserts everything. Any suggestions?

1 Answer 1

1

Is this what you're looking for?

$start = strpos($message,'<section>')+9;
$end = strpos($message,'<section/>');
$content = strip_tags(substr($message,$start,$end),"<br><p><u><span><hr>");

PS: Don't forget to sanitize!

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks Etherous for your suggestion. i tried this but it stripped from the email.
stripped everything from the email.
Oh, right. Include the permitted tags like you had in the question
yea i have that too but same. i analyze the email in outlook and i found that Microsoft stripped the open <section> tag but the closing one is there </section> :( .. in MySQL both of there are there. any other suggestion?
Sorry, when it's PHP, I have to get my hands on it to troubleshoot it. With this type of question, there's so many factors. If it were me, I would just use a form, and give them a textarea to enter their content
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.