We help IT Professionals succeed at work.
Get Started

How do I save the textarea (including any images) in WYMEditor using php

Russ Cummings
Last Modified: 2017-11-30
Just installed WYMEditor on a clients site. Using the 01-basic.html as the basis. My specific page is php, because I need to save the content to a MySql database field & mail() the content out.
here is the code:

ob_start(); // ensures anything dumped out will be caught

if(isset($_POST['new']) && $_POST['new']==1 && $errors =='')
$mm_date = date("Y-m-d H:i:s");
$body =$_REQUEST['body'];
$body = stripslashes($body);
$subject =$_REQUEST['subject'];
//send the email
// if ($_SESSION['username']<>'admin') {
$query = "SELECT email from users where username='".$_SESSION['username']."'"; 
$resultemail = mysql_query($query) or die ( mysql_error());
$rowemail = mysql_fetch_row($resultemail);
$too = $rowemail[0];
$from = $rowemail[0];

$username = $_SESSION['username'];

//send the email

                $to .= implode(", ", $_SESSION['emails']);
                $ffrom = "-f" . $from;
		$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';

$messageopen = "
<title>HTML email</title>

$messageclose = "

        $body = $messageopen.$body.$messageclose;

        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

		$headers .= "From: $from \r\n";
        $headers .= 'BCC: '. implode(",", $_SESSION['emails']) . "\r\n";
		$headers .= "Reply-To: $from \r\n";
		$headers .= "Return-Path: <bounced@fxxxxxxxxxx.com> /r/n";

                mail($too, $subject, $body, $headers, $ffrom);
        	while (ob_get_status()) 

$body = str_replace("'","`",$body);

                $ins_query="INSERT INTO mmerge(`mmdate`, `mmuser`, `mmsubject`, `mmbody`, `mmto`) VALUES ('$mm_date', '$username', '$subject', '$body', '$to')";
                mysql_query($ins_query) or die(mysql_error());
                header('Location: dashboard.php');
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="stylesheet" href="wymeditor/wymeditor/skins/default/skin.css">
    <link rel="stylesheet" href="css/simplestyle.css" /> 

<div class="ieform">

    <p><a href="http://www.wymeditor.org/">WYMeditor</a> is a web-based XHTML WYSIWYM editor.</p>
<form name="form" method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> 

<input type="hidden" name="new" value="1" />
<input type="text" name="subject" placeholder="Enter Subject*" size="30" required value="<?php echo $subject;?>" />
        <textarea name ="body" id="body" class="wymeditor">&lt;p&gt;Hello, World!&lt;/p&gt;</textarea>
        <input type="submit" class="wymupdate" value="Submit" />

    <script src="js/jquery.js"></script>
    <script src="wymeditor/wymeditor/jquery.wymeditor.js"></script>
    <script type="text/javascript">
$(document).ready(function() {

Open in new window

Except for the added Subject input, this is very similar to the example given.
What I need to do is assign the formatted textarea to the php variable $body.
It works, but only for the text, it doesn't contain the complete content, unlike the Preview button which is exactly what I want to send (including any images).

Watch Question
Most Valuable Expert 2017
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE