NYCPHP Meetup

NYPHP.org

[nycphp-talk] talk Digest, Vol 33, Issue 2

Nate Abele nate at cakephp.org
Wed Jul 1 12:21:59 EDT 2009


On Jul 1, 2009, at 12:00 PM, talk-request at lists.nyphp.org wrote:

> Date: Wed, 1 Jul 2009 11:32:44 -0400
> From: Randal Rust <randalrust at gmail.com>
> To: NYPHP Talk <talk at lists.nyphp.org>
> Subject: [nycphp-talk] Help Finding an HTML Email View in CakePHP
> 	Application
> Message-ID:
> 	<a9caffe50907010832h4cc6cc95w8290e1fcdd32ea71 at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> We have inherited a CakePHP application that sends a formatted HTML
> email when someone completes the site's registration process. The
> method that invokes the email is:
>
> $this->Invoice->send($districtInfo['District']['invoiceEmail'], 'PO
> Order', $insert_data)
>
> The problem I'm having is that I cannot find the view for the HTML
> formatting. If I look at the Invoice model, I cannot figure out where
> the code (see below) calls the view. This does not seem to follow
> anything that I see here:
>
> http://book.cakephp.org/view/269/Sending-a-basic-message
>
> ============================================
>
>       function send($email, $invoice_id, $insert_data)
>       {
>               if (! preg_match(VALID_EMAIL, $email)) {
>                       return false;
>               }
>               if (preg_match('/^[0-9]{1,10}$/', $invoice_id)) {
>                       $result = $this->find(('`Invoice`.`id` = ' .
> $invoice_id));
>               } else {
>                       $result = $this->find(('`Invoice`.`name` = "' .
> $this->mrClean->sql($invoice_id) . '"'));
>               }
>               if (empty($result)) {
>                       return false;
>               }
>
>               $tokens = array();
>               $replacements = array();
>               foreach ($insert_data as $key => $value) {
>                       $tokens[] = '%' . $key . '%';
>                       $replacements[] = $value;
>               }
>               $message = str_replace($tokens, $replacements,
> $result['Invoice']['invoice']);
>               $headers =      'MIME-Version: 1.0' . "\r\n" .
>               'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
>               'From: ' . $this->adminEmail . "\r\n" .
>               'Reply-To: ' . $this->adminEmail . "\r\n" .
>               'Bcc: ' . 'test at example.com' . "\r\n" .
>               'X-Mailer: PHP/' . phpversion();
>               if (mail($email, $result['Invoice']['name'], $message,  
> $headers,
> ('-f' . $this->adminEmail)) &&
>               mail($this->adminEmail, $result['Invoice']['name'],  
> $message,
> $headers, ('-f' . $this->adminEmail))) {
>                       return true;
>               } else {
>                       return false;
>               }
>       }
>
> Apologies to anyone on Evolt for the cross-post. That was not
> intentional. I picked the wrong email address.
>
> -- 
> Randal Rust
> R.Squared Communications
> www.r2communications.com
> 614-370-0036
>
>
> ------------------------------


This doesn't appear to follow normal CakePHP conventions on sending  
email, but it looks like the content is coming from $result['Invoice'] 
['invoice'], which is a Cake database result record.  FWIW, by  
convention, HTML email templates are stored in <app>/views/elements/ 
email/html.


- Nate Abele
   Lead Developer, CakePHP

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20090701/74d01822/attachment.html>


More information about the talk mailing list