Posted By

cshaiku on 06/30/09


Tagged

email Bash attachment


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

cshaiku
rickfu
irishsk
gecube


Email Attachment


 / Published in: PHP
 

URL: http://code.cshaiku.com/code_php_email_attachment.php

  1. #!/usr/local/bin/php
  2. <?php
  3.  
  4. $to = $argv[1];
  5. $subject = $argv[2];
  6. $attachmentName = $argv[3];
  7. $messageBoundry = md5(date('r', time()));
  8. $headers = "From: [email protected]
  9. Reply-To: from@somewher[email protected]";
  10. $headers .= "
  11. Content-Type: multipart/mixed; boundary=\"PHP-mixed-" . $messageBoundry . "\"";
  12. $attachment = chunk_split(base64_encode(file_get_contents($attachmentName)));
  13. ob_start(); //Turn on output buffering
  14.  
  15. ?>
  16. --PHP-mixed-<?= $messageBoundry ?>
  17. Content-Type: multipart/alternative; boundary="PHP-alt-<?= $messageBoundry; ?>"
  18.  
  19. --PHP-alt-<?=$messageBoundry?>
  20. Content-Type: text/plain; charset="iso-8859-1"
  21. Content-Transfer-Encoding: 7bit
  22.  
  23. --PHP-alt-<?= $messageBoundry ?>
  24. Content-Type: text/html; charset="iso-8859-1"
  25. Content-Transfer-Encoding: 7bit
  26.  
  27. <h3><?= $subject ?></h3>
  28.  
  29. --PHP-alt-<?= $messageBoundry ?>
  30.  
  31. <?= $subject ?>
  32.  
  33. --PHP-mixed-<?= $messageBoundry ?>
  34. Content-Type: application/zip; name="<?= $attachmentName ?>"
  35. Content-Transfer-Encoding: base64
  36. Content-Disposition: attachment
  37.  
  38. <?= $attachment ?>
  39.  
  40. --PHP-mixed-<?= $messageBoundry; ?>
  41.  
  42. <?php
  43.  
  44. $message = ob_get_clean();
  45. mail( $to, $subject, $message, $headers );
  46.  
  47. ?>

Report this snippet  

You need to login to post a comment.