NYCPHP Meetup

NYPHP.org

[nycphp-talk] Help Finding an HTML Email View in CakePHP Application

Randal Rust randalrust at gmail.com
Wed Jul 1 11:32:44 EDT 2009


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



More information about the talk mailing list