CodeThatEditor Example - Send e-mail
<php
require('code_html.php');
if (empty($_POST['to'])) {
?>
<html>
<head>
<title>Editor Send E-mail</title>
<script language="javascript1.2">
<!--
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" : "0<?php print($usecc==1);?>", "titlecc" : "CC:", "csscc" : "css",
"usebcc" : "0<?php print($usebcc==1);?>", "titlebcc" : "BCC:", "cssbcc" : "css",
"usefrom" : "0<?php print($usefrom==1);?>", "titlefrom" : "From:", "cssfrom" : "css",
"useattachments" : "0<?php print($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>
<style>
.css{font-family:Arial;font-size:12px;}
</style>
</head>
<body>
<form method=get>
<p class=css><b>Mail configure</b>:
<br>
Use CC <input type="checkbox" name="usecc" value="1"
<?php
if ($usecc == 1) print("checked");
?>>
Use BCC <input type="checkbox" name="usebcc" value="1"
<?php
if ($usebcc == 1) print("checked");
?>>
Use From <input type="checkbox" name="usefrom" value="1"
<?php
if ($usefrom == 1) print("checked");
?>>
Use Attachment <input type="checkbox" name="useattachments" value="1"
<?php
if ($useattachments == 1) print("checked");
?>>
<input type=submit value="Set" class=css>
</form>
<script language="javascript1.2">
<!--
var ed = new CEditor("Editor", editorDef);
ed.create(); // work with table
//-->
</script>
<pre>
</pre>
</body>
</html>
<?php
}
else{
/*
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')) {
if (filesize($file['tmp_name']) > 50*1028) die("Error! Too big file!");
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!");
};
?>
|