Guest User

Untitled

a guest
Jun 21st, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title> Sending Email </title>
  4. </head>
  5. <body>
  6. <?php
  7. // Read POST request params into global vars
  8. $to = $_POST['to'];
  9. $from = $_POST['from'];
  10. $subject = $_POST['subject'];
  11. $message = $_POST['message'];
  12.  
  13. // Obtain file upload vars
  14. $fileatt = $_FILES['fileatt']['tmp_name'];
  15. $fileatt_type = $_FILES['fileatt']['type'];
  16. $fileatt_name = $_FILES['fileatt']['name'];
  17.  
  18. $headers = "From: $from";
  19.  
  20. if (is_uploaded_file($fileatt)) {
  21. // Read the file to be attached ('rb' = read binary)
  22. $file = fopen($fileatt,'rb');
  23. $data = fread($file,filesize($fileatt));
  24. fclose($file);
  25.  
  26. // Generate a boundary string
  27. $semi_rand = md5(time());
  28. $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  29.  
  30. // Add the headers for a file attachment
  31. $headers .= "\nMIME-Version: 1.0\n" .
  32. "Content-Type: multipart/mixed;\n" .
  33. " boundary=\"{$mime_boundary}\"";
  34.  
  35. // Add a multipart boundary above the plain message
  36. $message = "This is a multi-part message in MIME format.\n\n" .
  37. "--{$mime_boundary}\n" .
  38. "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
  39. "Content-Transfer-Encoding: 7bit\n\n" .
  40. $message . "\n\n";
  41.  
  42. // Base64 encode the file data
  43. $data = chunk_split(base64_encode($data));
  44.  
  45. // Add file attachment to the message
  46. $message .= "--{$mime_boundary}\n" .
  47. "Content-Type: {$fileatt_type};\n" .
  48. " name=\"{$fileatt_name}\"\n" .
  49. //"Content-Disposition: attachment;\n" .
  50. //" filename=\"{$fileatt_name}\"\n" .
  51. "Content-Transfer-Encoding: base64\n\n" .
  52. $data . "\n\n" .
  53. "--{$mime_boundary}--\n";
  54. }
  55.  
  56. // Send the message
  57. $ok = @mail($to, $subject, $message, $headers);
  58. if ($ok) {
  59. echo "<p>Mail sent! Yay PHP!</p>";
  60. } else {
  61. echo "<p>Mail could not be sent. Sorry!</p>";
  62. }
  63. ?>
  64. </body>
  65. </html>
Add Comment
Please, Sign In to add comment