Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2015
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. <?php
  2. $htmlbody = " Your Mail Contant Here.... You can use html tags here...";
  3. $to = "ThomasQ111@gmail.com"; //Recipient Email Address
  4. $subject = "Test email with attachment"; //Email Subject
  5. $headers = "From: name@domain.com\r\nReply-To: name@domain.com";
  6. $random_hash = md5(date('r', time()));
  7. $headers .= "\r\nContent-Type: multipart/mixed;
  8. boundary=\"PHP-mixed-".$random_hash."\"";
  9. // Set your file path here
  10. $attachment = chunk_split(base64_encode(file_get_contents('screen1.png')));
  11.  
  12.  
  13. //define the body of the message.
  14. $message = "--PHP-mixed-$random_hash\r\n"."Content-Type: multipart/alternative;
  15. boundary=\"PHP-alt-$random_hash\"\r\n\r\n";
  16. $message .= "--PHP-alt-$random_hash\r\n"."Content-Type: text/plain;
  17. charset=\"iso-8859-1\"\r\n"."Content-Transfer-Encoding: 7bit\r\n\r\n";
  18.  
  19.  
  20. //Insert the html message.
  21. $message .= $htmlbody;
  22. $message .="\r\n\r\n--PHP-alt-$random_hash--\r\n\r\n";
  23.  
  24.  
  25. //include attachment
  26. $message .= "--PHP-mixed-$random_hash\r\n"."Content-Type: application/zip;
  27. name=\"screen1.png\"\r\n"."Content-Transfer-Encoding:
  28. base64\r\n"."Content-Disposition: attachment\r\n\r\n";
  29.  
  30. $message .= $attachment;
  31. $message .= "/r/n--PHP-mixed-$random_hash--";
  32.  
  33.  
  34. //send the email
  35. $mail = mail( $to, $subject , $message, $headers );
  36.  
  37. echo $mail ? "Mail sent" : "Mail failed";
  38. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement