Code: Select all
<?php
$from = $Sender;
$to = $EmailTo;
$subject = "RE: " . utf8_decode($EmailSubject);
$returnpath = explode("<", $from);
$returnpath = str_replace(">", "", $returnpath['1']);
$body .= utf8_decode($ActionTextField);
// Headers
$priority = "3";
$headers = "From: " . $from ."\n";
$headers .= "Cc: " . $emailcc ."\n";
$headers .= "Bcc: " . $emailbcc ."\n";
$headers .= "Reply-To: $emailfrom\n";
$headers .= "X-Sender: <$emailfrom>\n";
$headers .= "X-Mailer: PHP v" . phpversion() . "\n";
$headers .= "X-Priority: $priority\n"; //1 UrgentMessage, 3 Normal
// create a boundary string. It must be unique
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers .= "MIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
// Add a multipart boundary above the plain message
// $message ="This is a multi-part message in MIME format.\n\n";
$message ="--{$mime_boundary}\n";
//$message.="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$message.="Content-Type: text/plain; charset=\"unicode utf-8\"\n";
$message.="Content-Transfer-Encoding: 7bit\n\n";
$message .= str_replace("\n", "", $body)."\n";
$message .= "--PHP-alt-".$mime_boundary."--\n";
$fullfilepath = 'upload/' . $attachments;
// Read the file to be attached ('rb' = read binary)
$file = fopen($fullfilepath,'rb');
$data = fread($file,filesize($fullfilepath));
// Base64 encode the file data and identify the filetype using the returnMIMETYPE function
$data = chunk_split(base64_encode($data));
$mime = returnMIMEType($attachments);
// Add file attachment to the message
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$mime};\n" .
" name=\"{$attachments}\"\n" .
"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
//Sending part
if (!mail($to,$subject,$message,$headers,$returnpath)) {
echo '<div style="color:red;" align="right">Reply failed to be sent...</div><br/>';
} else {
echo '<div style="color:red;" align="right">Message sent...</div><br/>';
?>