note 82782 added to function.ob-start

From: Date: Fri, 25 Apr 2008 12:45:03 +0000
Subject: note 82782 added to function.ob-start
Groups: php.notes 
Request: Send a blank email to php-notes+get-138771@lists.php.net to get a copy of this message
I was seriously stuck trying to get marketing emails into a site so that the designer could edit them in Dreamweaver while my app could dynamically write and send them to customers. Then I discovered that this works - I barely believed how clever PHP could be! Hope this helps someone else. <?php class marketing_email{ function marketing_email($customer_id){ //---stuff to get customer details from DB------- //----stuff--- //I'm going to put 'newpart-' at the beginning and 'a' at the end of the separator string //I find that the 'a' is more reliable for a line end when it arrives at the client computer $random_hash = md5(date('r', time())); ob_start(); //Turn on output buffering ?> --newpart-<?php echo $random_hash; ?>a Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Dear <?php echo $customer_name ?> Your New special offer Blah Blah --newpart-<?php echo $random_hash; ?>a Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit <head> <style type="text/css"> <!-- p { font-family: Verdana, Arial, Helvetica, sans-serif; etc etc } --> </style> <title>Offer</title> </head> <body> Blah Blah Blah </body> --newpart-<?php echo $random_hash; ?>a-- <?php $pagecontent=ob_get_contents(); ob_end_clean(); //define the headers we want passed. Note that they are separated with \r\n $mail_headers = "MIME-Version: 1.0\r\nFrom: admin@domain.co.uk\r\nReply-To: admin@domain.co.uk"; //add boundary string and mime type specification $mail_headers .= "\r\nContent-Type: multipart/alternative;\r\n\tboundary=\"newpart-".$random_hash."a\""; $to=$customer_email; if(mail($to,"Offer",$pagecontent,$mail_headers)){ return TRUE; }else{ return FALSE; } } } ?> ---- Server IP: 92.48.100.16 Probable Submitter: 86.146.51.1 ---- Manual Page -- http://www.php.net/manual/en/function.ob-start.php Edit -- https://master.php.net/note/edit/82782 Del: integrated -- https://master.php.net/note/delete/82782/integrated Del: useless -- https://master.php.net/note/delete/82782/useless Del: bad code -- https://master.php.net/note/delete/82782/bad+code Del: spam -- https://master.php.net/note/delete/82782/spam Del: non-english -- https://master.php.net/note/delete/82782/non-english Del: in docs -- https://master.php.net/note/delete/82782/in+docs Del: other reasons-- https://master.php.net/note/delete/82782 Reject -- https://master.php.net/note/reject/82782 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#138771) next »