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

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:

<?php
session_start();
ob_start(); // ensures anything dumped out will be caught
require('db.php');

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 = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
";

$messageclose = "
</body>
</html>
";

        $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()) 
{
    ob_end_clean();
}

$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');
                exit();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <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" /> 
<title>Mailmerge</title>

</head>
<body>
<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;?>" />
<br>
        <textarea name ="body" id="body" class="wymeditor">&lt;p&gt;Hello, World!&lt;/p&gt;</textarea>
        <input type="submit" class="wymupdate" value="Submit" />
    </form>
<br>
</div>

    <script src="js/jquery.js"></script>
    <script src="wymeditor/wymeditor/jquery.wymeditor.js"></script>
    
    <script type="text/javascript">
$(document).ready(function() {
$('#body').wymeditor();
});
</script>
    
</body>
</html>

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).

Russ
Russ CummingsIT ConsulantAsked:
Who is Participating?
 
Julian HansenCommented:
I have given you the two options available.

Either you include a link to a browsable resource
Or you embed the image

That is it as far as embedding images in emails.
0
 
Julian HansenCommented:
Can you narrow down the question for us - it is not clear what you are asking. Reference to code and line numbers will help.

BTW I have added code tags to your post. Code tags make your code much easier to read and refer to - to add them highlight your code and click the CODE button in the toolbar.
0
 
Russ CummingsIT ConsulantAuthor Commented:
Julian,
When using WYMEditor I can paste Images & formatted text. When using the "Preview" button everything looks as it should.
But when I look at the saved result, it doesn't include the pasted image.
What I need to do is take the preview page & send it as the $body of the email.
I'm trying to use the WYMEditor as you're able to paste & send images / text in Gmail.
Hope this helps,

Russ
0
Network Scalability - Handle Complex Environments

Monitor your entire network from a single platform. Free 30 Day Trial Now!

 
Julian HansenCommented:
Ok, got it.
Two options

Option 1 (Recommended)
You need to make the src of the image an absolute URL - it can be to anywhere really - i.e. you can host the image anywhere - the absolute path means that wherever the email ends up it will be able to download the image and add it to the email

Option 2 (Not so much)
You can encode the image and embed it in the email using the base64 encoded format
<img src=" data:image/jpeg;base64...">

Open in new window


Sites like this one (https://www.base64-image.de/) can do the encoding for you.

Why Option 1 over Option 2 - simple - bandwidth. Without the image the email is small and quick to send - the choice of downloading the image is in the hands of the recipient - who should be used to it as this is how the majority of email embedded images are sent.
0
 
Russ CummingsIT ConsulantAuthor Commented:
Those are not an easy possibility. Users will paste images & text into WYMEditor for the purpose of sending an email.
Specifically is the ANY way to capture the Preview page & send that as an email - because the Preview is exactly what is desired?
Russ
0
 
Russ CummingsIT ConsulantAuthor Commented:
Understood.
Thank you Julian.
0
 
Julian HansenCommented:
You are welcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.