Advertisement
Guest User

SimpleInvoicesEmailPHPmail

a guest
Jan 14th, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.88 KB | None | 0 0
  1. //Define types of messages. For the use of simpleinvoices, only html messages will be sent.
  2. $htmlbody =
  3. "
  4. <h3>INVOICE</h3>
  5. <br />
  6. ---------------------------------------------------------
  7. <br />
  8. Invoice Summary
  9. <br />
  10. ---------------------------------------------------------
  11. <br />
  12. Invoice ID:
  13. "
  14. .
  15. $invoice['index_id']
  16. .
  17. "
  18. <br />
  19. Issue Date:
  20. "
  21. .
  22. $invoice['date']
  23. .
  24. "
  25. <br />
  26. Customer:
  27. "
  28. .
  29. $customer['name']
  30. .
  31. "
  32. <br />
  33. Amount:
  34. "
  35. .
  36. '$'.round($invoice['total'], 2)
  37. .
  38. "
  39. <br />
  40. Due:
  41. "
  42. .
  43. '15 days from '.$invoice['date'].' (Net 15)'
  44. .
  45.  
  46. "
  47. <br />
  48. Notes:
  49. "
  50. .
  51. $invoice['note']
  52. .
  53. "
  54. <br />
  55. <br />
  56. A detailed invoice is attached as a PDF.
  57. <br />
  58. <br />
  59. "
  60. .
  61. "
  62. ----------------------------------------------------------
  63. <br />
  64. "
  65. .
  66. $_POST['email_notes'];
  67.  
  68. $textmessage = $_POST['email_notes'];
  69. //define the receiver of the email
  70. $to = $_POST['email_to'];
  71. //define the subject of the email
  72. $subject = $_POST['email_subject'];
  73. //create a boundary string. It must be unique
  74. //so we use the MD5 algorithm to generate a random hash
  75. $random_hash = md5(date('r', time()));
  76. //define the headers we want passed. Note that they are separated with \r\n
  77. $headers = "From: " . $biller['name'] . "<" . $_POST['email_from'] . ">" . "\r\nReply-To: " . $_POST['email_from'] . "\r\nBcc: " . $_POST['email_bcc'];
  78. //add boundary string and mime type specification
  79. $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
  80. //read the atachment file contents into a string,
  81. //encode it with MIME base64,
  82. //and split it into smaller chunks
  83. $attachment = chunk_split(base64_encode(file_get_contents('./tmp/cache/' . $pdf_file_name))); ;
  84. //define the body of the message.
  85. $message = "--PHP-mixed-$random_hash\r\n"
  86. ."Content-Type: multipart/alternative; boundary=\"PHP-alt-$random_hash\"\r\n\r\n";
  87. $message .= "--PHP-alt-$random_hash\r\n"
  88. ."Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"
  89. ."Content-Transfer-Encoding: 7bit\r\n\r\n";
  90. //Insert the plain text message.
  91. $message .= strip_tags($textmessage);
  92. $message .= "\r\n\r\n--PHP-alt-$random_hash\r\n"
  93. ."Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
  94. ."Content-Transfer-Encoding: 7bit\r\n\r\n";
  95. //Insert the html message.
  96. $message .= $htmlbody;
  97. $message .="\r\n\r\n--PHP-alt-$random_hash--\r\n\r\n";
  98. //include attachment
  99. $message .= "--PHP-mixed-$random_hash\r\n"
  100. ."Content-Type: application/pdf; name=$pdf_file_name\r\n"
  101. ."Content-Transfer-Encoding: base64\r\n"
  102. ."Content-Disposition: attachment\r\n\r\n";
  103. $message .= $attachment;
  104. $message .= "/r/n--PHP-mixed-$random_hash--";
  105. //send the email
  106. $mail_sent = @mail( $to, $subject, $message, $headers );
  107. //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
  108. $sent = $mail_sent ? $pdf_file_name . " was sent to " . $_POST['email_to'] . " successfully." : "The invoice was not sent. Please try again.";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement