Created
February 20, 2014 15:11
-
-
Save tamboer/9115842 to your computer and use it in GitHub Desktop.
php mail test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $buyer_email = ""; | |
| //$buyer_email = ""; | |
| $supplier_email = ""; | |
| $supplier_email2 = ''; | |
| $lastInsertedID = 'mailtest from bewan with PDF'; | |
| $orderArray['order_date'] = '2014'; | |
| $pdfdoc = file_get_contents('yourfilename.pdf'); | |
| //$pdfdoc = 'null'; | |
| //var_dump($pdfdoc); | |
| phpMail($buyer_email, $supplier_email, $supplier_email2, $lastInsertedID, $orderArray, $pdfdoc); | |
| echo 'test'; | |
| function phpMail($buyer_email, $supplier_email, $supplier_email2, $lastInsertedID, $orderArray, $pdfdoc) | |
| { | |
| /* ==================== | |
| * set the location of installation | |
| * - retailservice.domain.com / domain.com/retailservices_demo and, | |
| * - mailtracker | |
| * | |
| * Prevent dummy orders going out to | |
| * real suppliers/buyers during testing | |
| * ==================== */ | |
| list($first, $second) = explode('/', $_SERVER['SCRIPT_NAME']); | |
| switch ($second) { | |
| case 'retailservices': | |
| $tracker = $_SERVER['HTTP_HOST'] . substr($_SERVER['SCRIPT_NAME'], 0, 27) . '/mail_tracker.php?id=' . $lastInsertedID; //retailservices/public_html on LIVE | |
| $live = true; | |
| break; | |
| case 'retailservices_demo': | |
| $tracker = $_SERVER['HTTP_HOST'] . substr($_SERVER['SCRIPT_NAME'], 0, 32) . '/mail_tracker.php?id=' . $lastInsertedID; //retailservices_demo/public_html on DEV | |
| $live = false; | |
| break; | |
| default: | |
| $tracker = $_SERVER['HTTP_HOST'] . '/mail_tracker.php?id=' . $lastInsertedID; //retailservices_demo/public_html on DEV | |
| $live = true; | |
| break; | |
| } | |
| //echo $live.' -- '.$tracker; | |
| /* ==================== | |
| * who gets the mail | |
| * ==================== */ | |
| $recipients = array('buyer'=>$buyer_email, 'supplier'=>$supplier_email, 'supplier2'=>$supplier_email2); | |
| foreach ($recipients as $key => $recipient) { | |
| /* ====================================================================== | |
| * Prevent dummy orders going out to real suppliers/buyers during testing | |
| * APPROVED_DEMO_RECIPIENTS is defined in connect.inc | |
| * ====================================================================== */ | |
| if ($recipient !== '') { | |
| if ($live === true) { | |
| $to = $recipient; | |
| } else { | |
| if (in_array($recipient, $GLOBALS['APPROVED_DEMO_RECIPIENTS']) || substr($recipient, -9) == '@bewan.be') | |
| $to = $recipient; | |
| } | |
| $subject = $_SESSION['language']['pdf']['subject'] . " " . $lastInsertedID . " (" . $orderArray['order_date'] . ")"; | |
| $message = " | |
| <p>" . $_SESSION['language']['pdf']['thx'] . "</p> | |
| <p>" . $_SESSION['language']['pdf']['order'] . "</p> | |
| "; | |
| /* ============================================= | |
| * Send click link in message to supplier - confirm receipt of the order | |
| * ============================================= */ | |
| if ($key == 'supplier' || $key == 'supplier2') { | |
| $confirm = ' | |
| <p> | |
| <a href="http://' . $tracker . | |
| '&confirmed=true¬ify=' . $buyer_email . | |
| '&lang=' . $_SESSION['buyer']['language'] . | |
| '&msg=' . $subject . | |
| '">' . | |
| $_SESSION['language']['order']['confirm'] . '</a> | |
| </p>'; | |
| }else if(is_numeric($key)){ | |
| $confirm = ''; | |
| } | |
| $message .= $confirm; | |
| $from = "[email protected]"; | |
| $headers = "From:" . $from; | |
| $separator = md5(time()); | |
| $eol = PHP_EOL; | |
| // main header | |
| $headers = "From: " . $from . $eol; | |
| $headers .= "MIME-Version: 1.0" . $eol; | |
| $headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\""; | |
| // no more headers after this, we start the body! // | |
| $filename = "order.pdf"; | |
| $attachment = chunk_split(base64_encode($pdfdoc)); | |
| $body = "--" . $separator . $eol; | |
| $body .= "Content-Type: multipart/alternative; boundary=\"" . $separator . "\""; | |
| $body .= "--" . $separator . $eol; | |
| $body .= "Content-Type: text/html; charset=\"iso-8859-1\"" . $eol; | |
| $body .= "Content-Transfer-Encoding: 8bit" . $eol . $eol; | |
| $body .= $message . $eol; | |
| // attachment | |
| $body .= "--" . $separator . $eol; | |
| $body .= "Content-Type: application/octet-stream; name=\"" . $filename . "\"" . $eol; | |
| $body .= "Content-Transfer-Encoding: base64" . $eol; | |
| $body .= "Content-Disposition: attachment" . $eol . $eol; | |
| $body .= $attachment . $eol; | |
| $body .= "--" . $separator . "--"; | |
| /* ==================== | |
| * send the mail | |
| * ==================== */ | |
| $result = mail($to, $subject, $body, $headers); | |
| } | |
| } | |
| if ($result) | |
| return true; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment