Narendra123

send email with attachment file

May 26th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. <?php
  2. if(isset($_POST['submit']))
  3. {
  4. //The form has been submitted, prep a nice thank you message
  5. $output = '<h1>Thanks for your file and message!</h1>';
  6. //Set the form flag to no display (cheap way!)
  7. $flags = 'style="display:none;"';
  8.  
  9. //Deal with the email
  10. $to = 'narendra.itechways@gmail.com';
  11. $subject = 'Way2course student details';
  12.  
  13. $message = strip_tags($_POST['fname']);
  14. $attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name'])));
  15. $filename = $_FILES['file']['name'];
  16.  
  17. $boundary =md5(date('r', time()));
  18.  
  19. $headers = "From: narendra.itechways@gmail.com\r\nReply-To: narendra.itechways@gmail.com";
  20. $headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";
  21.  
  22. $message="This is a multi-part message in MIME format.
  23.  
  24. --_1_$boundary
  25. Content-Type: multipart/alternative; boundary=\"_2_$boundary\"
  26.  
  27. --_2_$boundary
  28. Content-Type: text/plain; charset=\"iso-8859-1\"
  29. Content-Transfer-Encoding: 7bit
  30.  
  31. $message
  32.  
  33. --_2_$boundary--
  34. --_1_$boundary
  35. Content-Type: application/octet-stream; name=\"$filename\"
  36. Content-Transfer-Encoding: base64
  37. Content-Disposition: attachment
  38.  
  39. $attachment
  40. --_1_$boundary--";
  41.  
  42. if(mail($to, $subject, $message, $headers)){
  43. echo "sent";
  44. }else{
  45. echo "fail";
  46. }
  47. }
  48. ?>
Add Comment
Please, Sign In to add comment