You are here

Sent email & attachment

<?php
$path
= "path/to/file/"; // path to file
$filename = "file.fta"; // file to attach
$file = $path.$filename;
$content = file_get_contents( $file);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$name = basename($file);
$from_name = "sender name";
$from_mail = "senderemail@example.com";
$message = "nice and very important text here";
$mailto = "reciver1@example.com";
$cc= "reciver2@example.com";
$replyto= "replyto@example.com";
$subject = "What is it about";

// header
$header = "From: ".$from_name." <".$from_mail.">\r\n";
$header .= "Cc: "." <".$cc.">\r\n";
$header .= "Reply-To: ".$replyto."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary="".$uid.""\r\n\r\n";

// message & attachment
$nmessage = "--".$uid."\r\n";
$nmessage .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$nmessage .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$nmessage .= $message."\r\n\r\n";
$nmessage .= "--".$uid."\r\n";
$nmessage .= "Content-Type: application/octet-stream; name="".$filename.""\r\n";
$nmessage .= "Content-Transfer-Encoding: base64\r\n";
$nmessage .= "Content-Disposition: attachment; filename="".$filename.""\r\n\r\n";
$nmessage .= $content."\r\n\r\n";
$nmessage .= "--".$uid."--";

// sending the email and error management
if (mail($mailto, $subject, $nmessage, $header)) {
    return
true; // Or do something here
} else {
  return
false// Or do something here
}
?>
code type: