Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $name = "myname";
- $to = "receive@gmail.com";
- $email = "sender@gmail.com";
- $from = "myname";
- $subject = "Here is your attachment";
- $mainMessage = "Hi, here's the file.";
- $fileatt = $_SERVER['DOCUMENT_ROOT']."/xxx/ticket.pdf";
- $fileatttype = "application/pdf";
- $fileattname = "ticket.pdf";
- $headers = "From: $from";
- // File
- $file = fopen($fileatt, 'rb');
- $data = fread($file, filesize($fileatt));
- fclose($file);
- // This attaches the file
- $semi_rand = md5(time());
- $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
- $headers .= "nMIME-Version: 1.0n" .
- "Content-Type: multipart/mixed;n" .
- " boundary="{$mime_boundary}"";
- $message = "This is a multi-part message in MIME format.nn" .
- "-{$mime_boundary}n" .
- "Content-Type: text/html; charset="iso-8859-1n" .
- "Content-Transfer-Encoding: 7bitnn" .
- $mainMessage . "nn";
- $data = chunk_split(base64_encode($data));
- $message .= "--{$mime_boundary}n" .
- "Content-Type: {$fileatttype};n" .
- " name="{$fileattname}"n" .
- "Content-Disposition: attachment;n" .
- " filename="{$fileattname}"n" .
- "Content-Transfer-Encoding: base64nn" .
- $data . "nn" .
- "-{$mime_boundary}-n";
- // Send the email
- if(mail($to, $subject, $message, $headers)) {
- echo "The email was sent.";
- }
- else {
- echo "There was an error sending the mail.";
- }
- ?>
Add Comment
Please, Sign In to add comment