Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- </pre>
- <?php
- //
- // copyright StringCat, Amsterdam 2012
- //
- /*
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- //
- // simple email script using php mail with all possibilities:
- // -multiple recipients
- // -multiple cc
- // -multiple bcc
- // -specified reply-to address
- // -attached file(s)
- //
- // just comment out a certain feature if you do not need it
- // WARNING
- // php mail() function only works if in the php.ini the smtp server is
- // is set, from the domain where this script is invoked
- // php mail() does not support smtp authemtification
- //
- //
- // if you want to scale this script up, associative arrays should be used
- // if you want to use less features, comment out what you do not want
- //
- // find location of script
- $path_info = pathinfo(__FILE__);
- $dir = $path_info['dirname'];
- chdir($dir);
- //
- // subject , body
- //
- $emailSubject = 'Subject'; // replace with your own
- $messageBody = 'This is the message'; // replace with your own
- //
- // sender
- //
- $fromEmailAddress = 'fromMe@example.com'; // replace with your own
- $fromEmailName = 'My Name'; // replace with your own
- $replyToEmailAddress = 'reply@domain.com'; // replace with your own
- $replyToEmailName = 'MyReplyAddress'; // replace with your own
- //
- // recipients (add more if you need)
- //
- $toEmailAddress1 = 'recipient1@hisdomain.com'; // replace with your own
- $toEmailName1 = 'firstRecipient'; // replace with your own
- $toEmailFull1 = $toEmailName1 . ' <'. $toEmailAddress1 .'>';
- $toEmailAddress2 = 'secondRecioient@herdomain.com'; // replace with your own
- $toEmailName2 = 'secondRecipient'; // replace with your own
- $toEmailFull2 = "$toEmailName2 <$toEmailAddress2>";
- //
- // cc's
- //
- $ccEmailAddress1 = 'cc1@cc1domain.com'; // replace with your own
- $ccEmailName1 = 'first CC'; // replace with your own
- $ccEmailAddress2 = 'cc2@cc2domain.com'; // replace with your own
- $ccEmailName2 = 'second CC'; // replace with your own
- //
- // bcc's
- //
- $bccEmailAddress1 = 'bcc1@bcc1domain.com'; // replace with your own
- $bccEmailName1 = 'first BCC'; // replace with your own
- $bccEmailAddress2 = 'bcc2@bcc2domain.com'; // replace with your own
- $bccEmailName2 = 'second BCC'; // replace with your own
- //
- // attachment 1
- //
- // replace with your own filename and mime-type
- // file must be physically present at file location
- // of this script
- //
- $attachmentShortFileName1 = "test.pdf"; // replace with your own
- $attachmentFileName1 = $dir. "/".$attachmentShortFileName1;
- $attachment1 = file_get_contents($attachmentFileName1);
- $b64Attachment1 = chunk_split(base64_encode($attachment1));
- $mimeType1 = "application/pdf"; // replace with your own
- $attachmentShortFileName2 = "test.doc"; // replace with your own
- $attachmentFileName2 = $dir. "/". $attachmentShortFileName2 ;
- $attachment2 = file_get_contents($attachmentFileName2);
- $b64Attachment2 = chunk_split(base64_encode($attachment2));
- $mimeType2 = "application/msword"; // replace with your own
- //
- // headers input
- //
- // comment out if not used
- //
- $headers = "From: " . $fromEmailName . " <" . $fromEmailAddress . ">" . "\r\n" ;
- $headers.= "Reply-To: " . $replyToEmailName . " <" . $replyToEmailAddress . ">" . "\r\n" ;
- $headers.= "cc: " . $ccEmailName1 . " <" . $ccEmailAddress1 . ">" . "\r\n" ;
- $headers.= "cc: " . $ccEmailName2 . " <" . $ccEmailAddress2 . ">" . "\r\n" ;
- $headers.= "bcc: " . $bccEmailName1 . " <" . $bccEmailAddress1 . ">" . "\r\n" ;
- $headers.= "bcc: " . $bccEmailName2 . " <" . $bccEmailAddress2 . ">" . "\r\n" ;
- // Generate a mime boundary string
- $rnd_str = md5(time());
- $mime_boundary = "==Multipart_Boundary_x{$rnd_str}x";
- // Add headers for file attachment
- $headers .= "MIME-Version: 1.0\n" .
- "Content-Type: multipart/mixed;\n" .
- " boundary=\"{$mime_boundary}\"";
- // Add a multipart boundary above the plain message
- $body = "This is a multi-part message in MIME format.\r\n\r\n" .
- "--{$mime_boundary}\r\n" .
- "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n" .
- "Content-Transfer-Encoding: 7bit\r\n\r\n" .
- $messageBody . "\r\n\r\n";
- // Add first file attachment to the message
- $body .= "--{$mime_boundary}\r\n" .
- "Content-Type: {$mimeType1};\r\n" .
- " name=\"{$attachmentShortFileName1}\"\r\n" .
- "Content-Disposition: attachment;\r\n" .
- " filename=\"{$attachmentShortFileName1}\"\r\n" .
- "Content-Transfer-Encoding: base64\r\n\r\n" .
- $b64Attachment1 . "\r\n\r\n" .
- //
- // comment out one of the two following lines
- // dependent on number of attached files
- // last mime boundary must end in "--"
- //
- "--{$mime_boundary}\r\n";
- // "--{$mime_boundary}--\r\n";
- //
- // Add second file attachment to the message
- $body .="Content-Type: {$mimeType2};\r\n" .
- " name=\"{$attachmentShortFileName2}\"\r\n" .
- "Content-Disposition: attachment;\r\n" .
- " filename=\"{$attachmentShortFileName2}\"\r\n" .
- "Content-Transfer-Encoding: base64\r\n\r\n" .
- $b64Attachment2 . "\r\n\r\n" .
- //
- // comment out one of the two following lines
- // dependent on number of attached files
- // last mime boundary must end in "--"
- //
- // "--{$mime_boundary}\r\n";
- "--{$mime_boundary}--\r\n";
- $return = mail( "$toEmailFull1, $toEmailFull2 " , $emailSubject, $body, $headers );
- // catch return code if you can do something useful with it
- ?>
- <pre>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement