Editor Sending Mail
Editor it is possible to use for sending mail in RTF format.
At the example below we use PHP as web-script language. But you can choose your own favorite web-script language. Here we just try to show basic principles.
Send E-mail from the Editor
For this purpose it is required to set property useMail in true and define properties of object mailDef
The object mailDef defines what fields will be used at sending mail, the name of the form and a file handler.
Possible fields are subject, to, cc, bcc, from and attachment.
To configure editor for send mail you should define such proprties in editorDef object
/*Boolean (optional) indicates will editor use for send e-mail*/
useMail : true,
/*Object (optional) property defines appearance, layout and other properties for e-mail sending*/
mailDef : {
/*Subject definition*/
"usesubject" : true,
"titlesubject" : "Subject:",
"csssubject" : "css",
/*To (e-mail recipient) definition*/
"useto" : true,
"titleto" : "To:",
"cssto" : "css",
/*CC (copy e-mail recipient) definition*/
"usecc" : true,
"titlecc" : "CC:",
"csscc" : "css",
/*BCC (black copy e-mail recipient) definition*/
"usebcc" : true,
"titlebcc" : "BCC:",
"cssbcc" : "css",
/*From (e-mail sender) definition*/
"usefrom" : true,
"titlefrom" : "From:",
"cssfrom" : "css",
/*Attachment definition*/
"useattachments" : true,
"titleattachments" : "Attach file (<=50Kb): ",
"cssattachments" : "css",
/*Button definition to use in toolbar to send e-mail*/
"mailIcon" : {
name : "mail", text : "Send e-mail", img_on : {
src : 'img/post_button_send.gif', width : 22, height : 22
}
},
"mailForm" : "emailform", //String defines name of form that will post
"mailAction" : "mail_ex.php", //String defines action of form and server handler of e-mail
"mailLayout" : "top" //Layout of e-mail panel [top, bottom]
}
|
Property use* Boolean and indicates will subject field uses, title* String defines title for field subject, css* String defines css class for title and field
Next step - we create .php script. Result of this script is sending e-mail.
<?php
/*
send mail
possible parameters : subject, to, cc, bcc, from, attachments
*/
$uploadfolder = "upload";
$file = $HTTP_POST_FILES['attachments'];
$headers = "";
$email_message = "";
if (!empty($file['tmp_name']) && ($file['tmp_name'] != 'none')) {
/* add attachment */
if (move_uploaded_file($file['tmp_name'], $uploadfolder . "/" . $file['name'])) {
$file['fullname'] = $uploadfolder . "/" . $file['name'];
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "MIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$fp = fopen($file['fullname'], 'rb');
$data = fread($fp, filesize($file['fullname']));
fclose($fp);
$data = chunk_split(base64_encode($data));
/* set enconding for multipart e-mail*/
$email_message .= "--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$body . "\n\n";
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: ".$file['type'].";\n" .
" name=\"".$file['name']."\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}\n";
};
};
/* set enconding */
if (empty($headers)) $headers = "Content-Type: text/html; charset=iso-8859-1\n";
if (empty($email_message)) $email_message = $body;
if (!empty($from)) $headers .= "From:$from\n";
if (!empty($cc)) $headers .= "cc:$cc\n";
if (!empty($bcc)) $headers .= "bcc:$bcc\n";
/* and now mail it */
mail($to, $subject, $email_message, $headers) or die("Error! Can't send mail!");
print("Mail send succesfully!");
?>
|
Note: If you will use attachments you server have to be confugured for upload files.
And finally we complete a web page for editor script:
<html>
<head>
<title>Editor Send E-mail</title>
<script language="javascript" src="/codethatsdk.js"></script>
<script language="javascript" src="codethateditorpro.js"></script>
<script language="javascript1.2">
<!--
var editorDef = {
text : "",
style : {
width : '400',
height : '200',
defaultClass : {
backgroundcolor : "#ffffff", bordercolor : "#efefe0",
borderstyle : "inset", borderwidth : 2
}
},
useMail : 1,
mailDef : {
"usesubject" : 1, "titlesubject" : "Subject:", "csssubject" : "css",
"useto" : "1", "titleto" : "To:", "cssto" : "css",
"usecc" : "1", "titlecc" : "CC:", "csscc" : "css",
"usebcc" : "1", "titlebcc" : "BCC:", "cssbcc" : "css",
"usefrom" : "1", "titlefrom" : "From:", "cssfrom" : "css",
"useattachments" : "1", "titleattachments" : "Attach file (<=50Kb): ",
"cssattachments" : "css",
"mailIcon" : {
name : "mail", text : "Send e-mail", img_on : {
src : 'img/post_button_send.gif',
width : 22, height : 22
}
},
mailForm : "emailform",
mailAction : "mail_ex.php",
mailLayout : "top"
}
};
//-->
</script>
</head>
<body>
<script language="javascript1.2">
<!--
var ed = new CEditor("Editor", editorDef);
ed.create(); // work with table
//-->
</script>
</body>
</html>
|
Example - Send e-mail
You can see an example and complete code here - E-mail sending [popup]
Read more about CodeThatEditor >>
|