Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('display_errors',1); // enable php error display for easy trouble shooting
- error_reporting(E_ALL); // set error display to all
- $to = "recipient@domain.com"; // change accordingly
- $from ="sender@domain.com"; // change accordingly
- $subject = "Your Email Subject"; // change accordingly
- $bodytext = "Your Email Message"; // change accordingly
- $filepath = "image.jpg"; // Path to the file (example)
- $filetype = "application/jpg"; // File Type
- $filename = "image.jpg"; // Filename that will be used for the file as the attachment
- // boundary
- $semi_rand = md5(time());
- $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
- $headers= "From:" . $from;
- // headers for attachment
- $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
- // multipart boundary
- $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $bodytext . "\n\n";
- $message .= "--{$mime_boundary}\n";
- $file = fopen($filepath,'rb');
- $data = fread($file,filesize($filepath));
- fclose($file);
- $data = chunk_split(base64_encode($data));
- $message .= "Content-Type: {'application/octet-stream'};\n" . " name=\"$filename\"\n" .
- "Content-Disposition: attachment;\n" . " filename=\"$filename\"\n" .
- "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
- $message .= "--{$mime_boundary}\n";
- if (mail($to,$subject,$message,$headers)) {
- echo 'Successfully Sent';
- } else {
- echo 'Message Sending Failed';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement