Changeset 38 for trunk/lib/Email.inc.php


Ignore:
Timestamp:
Dec 15, 2005 1:28:09 AM (18 years ago)
Author:
scdev
Message:

added extra headers option to Email:: and fixed confusion over \r\n

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Email.inc.php

    r37 r38  
    3636        'from' => null,
    3737        'subject' => null,
     38        'headers' => null,
    3839        'regex' => null
    3940    );
     
    207208     * @since   28 Nov 2005 12:56:09
    208209     */
    209     function send($to=null, $from=null, $subject=null)
     210    function send($to=null, $from=null, $subject=null, $headers=null)
    210211    {
    211212        // Use arguments if provided.
     
    219220             $this->setParam(array('subject' => $subject));
    220221        }
     222        if (isset($headers)) {
     223             $this->setParam(array('headers' => $headers));
     224        }
    221225
    222226        // Ensure required values exist.
     
    248252       
    249253        // From headers are custom headers.
    250         $headers = sprintf("From: %s\r\n\r\n", $this->_params['from']);
     254        $headers = array('From' => $this->_params['from']);
     255
     256        // Additional headers.
     257        if (isset($this->_params['headers']) && is_array($this->_params['headers'])) {
     258            $headers = array_merge($this->_params['headers'], $headers);
     259        }
     260       
     261        // Process headers.
     262        $final_headers = array();
     263        foreach ($headers as $key => $val) {
     264            $final_headers[] = sprintf('%s: %s', $key, $val);
     265        }
     266        $final_headers = join("\r\n", $final_headers);
    251267       
    252268        // This is the address where delivery problems are sent to. We must strip off everything except the local@domain part.
     
    254270       
    255271        // Check for mail header injection attacks.
    256         $full_mail_content = join("\n", array($final_to, $this->_params['subject'], $final_body, $headers, $envelope_sender_header));
     272        $full_mail_content = join("\n", array($final_to, $this->_params['subject'], $final_body, $final_headers, $envelope_sender_header));
    257273        if (preg_match("/(Content-Type:|MIME-Version:|Content-Transfer-Encoding:|[\n\r]Bcc:|[\n\r]Cc:)/i", $full_mail_content)) {
    258274            App::logMsg(sprintf('Mail header injection attack in content: %s', $full_mail_content), LOG_WARNING, __FILE__, __LINE__);
     
    262278
    263279        // Ensure message was successfully accepted for delivery.
    264         if (!mail($final_to, $this->_params['subject'], $final_body, $headers, $envelope_sender_header)) {
    265             App::logMsg(sprintf('Email failure with parameters: %s, %s, %s, %s', $this->_params['to'], $this->_params['subject'], str_replace("\r\n", '', $headers), $envelope_sender_header), LOG_NOTICE, __FILE__, __LINE__);
     280        if (!mail($final_to, $this->_params['subject'], $final_body, $final_headers, $envelope_sender_header)) {
     281            App::logMsg(sprintf('Email failure with parameters: %s, %s, %s, %s', $this->_params['to'], $this->_params['subject'], str_replace("\r\n", '', $final_headers), $envelope_sender_header), LOG_NOTICE, __FILE__, __LINE__);
    266282            return false;
    267283        }
Note: See TracChangeset for help on using the changeset viewer.