Advertisement
Guest User

test mail

a guest
Jan 28th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.75 KB | None | 0 0
  1. </pre>
  2. <?php
  3.  
  4. //
  5. // copyright StringCat, Amsterdam 2012
  6. //
  7. /*
  8. This program is free software: you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation, either version 3 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. //
  22. // simple email script using php mail with all possibilities:
  23. // -multiple recipients
  24. // -multiple cc
  25. // -multiple bcc
  26. // -specified reply-to address
  27. // -attached file(s)
  28. //
  29.  
  30. // just comment out a certain feature if you do not need it
  31. // WARNING
  32. // php mail() function only works if in the php.ini the smtp server is
  33. // is set, from the domain where this script is invoked
  34. // php mail() does not support smtp authemtification
  35. //
  36.  
  37. //
  38. // if you want to scale this script up, associative arrays should be used
  39. // if you want to use less features, comment out what you do not want
  40. //
  41. // find location of script
  42. $path_info = pathinfo(__FILE__);
  43. $dir = $path_info['dirname'];
  44. chdir($dir);
  45.  
  46. //
  47. // subject , body
  48. //
  49. $emailSubject = 'Subject'; // replace with your own
  50. $messageBody = 'This is the message'; // replace with your own
  51. //
  52. // sender
  53. //
  54. $fromEmailAddress = 'fromMe@example.com'; // replace with your own
  55. $fromEmailName = 'My Name'; // replace with your own
  56. $replyToEmailAddress = 'reply@domain.com'; // replace with your own
  57. $replyToEmailName = 'MyReplyAddress'; // replace with your own
  58. //
  59. // recipients (add more if you need)
  60. //
  61. $toEmailAddress1 = 'recipient1@hisdomain.com'; // replace with your own
  62. $toEmailName1 = 'firstRecipient'; // replace with your own
  63. $toEmailFull1 = $toEmailName1 . ' <'. $toEmailAddress1 .'>';
  64. $toEmailAddress2 = 'secondRecioient@herdomain.com'; // replace with your own
  65. $toEmailName2 = 'secondRecipient'; // replace with your own
  66. $toEmailFull2 = "$toEmailName2 <$toEmailAddress2>";
  67. //
  68. // cc's
  69. //
  70. $ccEmailAddress1 = 'cc1@cc1domain.com'; // replace with your own
  71. $ccEmailName1 = 'first CC'; // replace with your own
  72. $ccEmailAddress2 = 'cc2@cc2domain.com'; // replace with your own
  73. $ccEmailName2 = 'second CC'; // replace with your own
  74. //
  75. // bcc's
  76. //
  77. $bccEmailAddress1 = 'bcc1@bcc1domain.com'; // replace with your own
  78. $bccEmailName1 = 'first BCC'; // replace with your own
  79. $bccEmailAddress2 = 'bcc2@bcc2domain.com'; // replace with your own
  80. $bccEmailName2 = 'second BCC'; // replace with your own
  81. //
  82. // attachment 1
  83. //
  84. // replace with your own filename and mime-type
  85. // file must be physically present at file location
  86. // of this script
  87. //
  88. $attachmentShortFileName1 = "test.pdf"; // replace with your own
  89. $attachmentFileName1 = $dir. "/".$attachmentShortFileName1;
  90. $attachment1 = file_get_contents($attachmentFileName1);
  91. $b64Attachment1 = chunk_split(base64_encode($attachment1));
  92. $mimeType1 = "application/pdf"; // replace with your own
  93.  
  94. $attachmentShortFileName2 = "test.doc"; // replace with your own
  95. $attachmentFileName2 = $dir. "/". $attachmentShortFileName2 ;
  96. $attachment2 = file_get_contents($attachmentFileName2);
  97. $b64Attachment2 = chunk_split(base64_encode($attachment2));
  98. $mimeType2 = "application/msword"; // replace with your own
  99.  
  100. //
  101. // headers input
  102. //
  103. // comment out if not used
  104. //
  105. $headers = "From: " . $fromEmailName . " <" . $fromEmailAddress . ">" . "\r\n" ;
  106. $headers.= "Reply-To: " . $replyToEmailName . " <" . $replyToEmailAddress . ">" . "\r\n" ;
  107. $headers.= "cc: " . $ccEmailName1 . " <" . $ccEmailAddress1 . ">" . "\r\n" ;
  108. $headers.= "cc: " . $ccEmailName2 . " <" . $ccEmailAddress2 . ">" . "\r\n" ;
  109. $headers.= "bcc: " . $bccEmailName1 . " <" . $bccEmailAddress1 . ">" . "\r\n" ;
  110. $headers.= "bcc: " . $bccEmailName2 . " <" . $bccEmailAddress2 . ">" . "\r\n" ;
  111.  
  112. // Generate a mime boundary string
  113. $rnd_str = md5(time());
  114. $mime_boundary = "==Multipart_Boundary_x{$rnd_str}x";
  115. // Add headers for file attachment
  116. $headers .= "MIME-Version: 1.0\n" .
  117. "Content-Type: multipart/mixed;\n" .
  118. " boundary=\"{$mime_boundary}\"";
  119. // Add a multipart boundary above the plain message
  120. $body = "This is a multi-part message in MIME format.\r\n\r\n" .
  121. "--{$mime_boundary}\r\n" .
  122. "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n" .
  123. "Content-Transfer-Encoding: 7bit\r\n\r\n" .
  124. $messageBody . "\r\n\r\n";
  125. // Add first file attachment to the message
  126. $body .= "--{$mime_boundary}\r\n" .
  127. "Content-Type: {$mimeType1};\r\n" .
  128. " name=\"{$attachmentShortFileName1}\"\r\n" .
  129. "Content-Disposition: attachment;\r\n" .
  130. " filename=\"{$attachmentShortFileName1}\"\r\n" .
  131. "Content-Transfer-Encoding: base64\r\n\r\n" .
  132. $b64Attachment1 . "\r\n\r\n" .
  133. //
  134. // comment out one of the two following lines
  135. // dependent on number of attached files
  136. // last mime boundary must end in "--"
  137. //
  138. "--{$mime_boundary}\r\n";
  139. // "--{$mime_boundary}--\r\n";
  140. //
  141. // Add second file attachment to the message
  142. $body .="Content-Type: {$mimeType2};\r\n" .
  143. " name=\"{$attachmentShortFileName2}\"\r\n" .
  144. "Content-Disposition: attachment;\r\n" .
  145. " filename=\"{$attachmentShortFileName2}\"\r\n" .
  146. "Content-Transfer-Encoding: base64\r\n\r\n" .
  147. $b64Attachment2 . "\r\n\r\n" .
  148. //
  149. // comment out one of the two following lines
  150. // dependent on number of attached files
  151. // last mime boundary must end in "--"
  152. //
  153. // "--{$mime_boundary}\r\n";
  154. "--{$mime_boundary}--\r\n";
  155.  
  156. $return = mail( "$toEmailFull1, $toEmailFull2 " , $emailSubject, $body, $headers );
  157. // catch return code if you can do something useful with it
  158. ?>
  159. <pre>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement