Use PHPMailer in oscommerce

The contribution is used to use PHPMailer Class in oscommerce to send email. 

If you want to use your smtp server to send email, you can get it helpful.

-----------------------
Instruction to Install
-----------------------

Database : Import the sql file [phpmailer.sql] to your database 

*******************
File Installation
*******************
WARNING: KEEP BACKUP OF YOUR OSCOMMERCE FILES BEFORE INSTALLING IT.

Replace all the files in catlog directory if you have Fresh Installation of Oscommerce.


If your oscommerce is customized or modified, use the following steps for manual Installation:

1. Copy the directory and files of /catalog/includes/classes/phpmailer to /catalog/includes/classes/ directory

2. Copy the directory and files of /catalog/admin/includes/classes/phpmailer to /catalog/admin/includes/classes/ directory

3. Open the file catalog/admin/includes/application_top.php in your instalation.

 Find The following text there:

 require(DIR_WS_FUNCTIONS . 'html_output.php');
    
  And add the following code block after it :
  
  //--------------------------------------------------------------------------------------------
    // BOF : Phpmailer for smtp
    // initialize phpmailer class
      if(EMAIL_USE_PHPMAILER == 'true')
      {  
        require_once(DIR_WS_CLASSES . 'phpmailer/class.phpmailer.php');
      }
    // EOF : Phpmailer for smtp  
  //---------------------------------------------------------------------------------------------


4. Open the file catalog/includes/application_top.php in your instalation

 Find The following text there:

 require(DIR_WS_FUNCTIONS . 'html_output.php');
    
  And add the following code block after it :
  
  //--------------------------------------------------------------------------------------------
    // BOF : Phpmailer for smtp
    // initialize phpmailer class
      if(EMAIL_USE_PHPMAILER == 'true')
      {  
        require_once(DIR_WS_CLASSES . 'phpmailer/class.phpmailer.php');
      }
    // EOF : Phpmailer for smtp  
  //---------------------------------------------------------------------------------------------
  
5. Open the file catalog/admin/includes/functions/general.php in your instalation

 Find The following text:

function tep_mail($to_name, $to_email_address, $email_subject, $email_text, $from_email_name, $from_email_address) {
    if (SEND_EMAILS != 'true') return false;
    
  And add the following code block after it :
  
//------------------------------------------------------------------------  
// BOF : Phpmailer for smtp
    if(EMAIL_USE_PHPMAILER == 'true')
    {
      $mailer = new PHPMailer;
      $mailer->AddAddress($to_email_address, $to_name);
      $mailer->AddReplyTo($from_email_address, $from_email_name);
      $mailer->FromName = $from_email_name;
      $mailer->From = $from_email_address;
      
      if (EMAIL_USE_HTML == 'true') 
      {
        $order   = array("\r\n", "\n", "\r");
        $replace = '<br />';

        // Processes \r\n's first so they aren't converted twice.
        $email_text = str_replace($order, $replace, $email_text);
        $mailer->IsHTML(true);
      }
      if(EMAIL_PHPMAILER_OPTIONS == 'smtp')
      {
        $mailer->IsSMTP(true);
        $mailer->Host = EMAIL_PHPMAILER_SMTP_HOST;
        $mailer->Port = EMAIL_PHPMAILER_SMTP_PORT;
        
        $mailer->SMTPDebug = false;
        
        $mailer->Username = EMAIL_PHPMAILER_SMTP_USERNAME;
        $mailer->Password = EMAIL_PHPMAILER_SMTP_PASSWORD;
        
        if(EMAIL_PHPMAILER_SMTP_AUTH == 'true')
        {
          $mailer->SMTPAuth = true;
        }
        if(EMAIL_PHPMAILER_SMTP_SSL == 'true')
        {
          $mailer->SMTPSecure = "ssl";
        }
        
        $mailer->Hostname = EMAIL_PHPMAILER_SMTP_HOST;
      }
      
      $mailer->Body = stripslashes($email_text);
      $mailer->Subject = stripslashes($email_subject);
      
      if($mailer->Send())
        return true;
      
      return false;
    }
    // EOF : Phpmailer for smtp
//------------------------------------------------------------------------------------------------    

6. Open the file catalog/includes/functions/general.php in your instalation
 Find The following text there:

  function tep_mail($to_name, $to_email_address, $email_subject, $email_text, $from_email_name, $from_email_address) {
    if (SEND_EMAILS != 'true') return false;
    
  And add the following code block after it :
  
//------------------------------------------------------------------------
// BOF : Phpmailer for smtp
    if(EMAIL_USE_PHPMAILER == 'true')
    {
      $mailer = new PHPMailer;
      $mailer->AddAddress($to_email_address, $to_name);
      $mailer->AddReplyTo($from_email_address, $from_email_name);
      $mailer->FromName = $from_email_name;
      $mailer->From = $from_email_address;
      
      if (EMAIL_USE_HTML == 'true') 
      {
        $order   = array("\r\n", "\n", "\r");
        $replace = '<br />';

        // Processes \r\n's first so they aren't converted twice.
        $email_text = str_replace($order, $replace, $email_text);
        $mailer->IsHTML(true);
      }
      if(EMAIL_PHPMAILER_OPTIONS == 'smtp')
      {
        $mailer->IsSMTP(true);
        $mailer->Host = EMAIL_PHPMAILER_SMTP_HOST;
        $mailer->Port = EMAIL_PHPMAILER_SMTP_PORT;
        
        $mailer->SMTPDebug = false;
        
        $mailer->Username = EMAIL_PHPMAILER_SMTP_USERNAME;
        $mailer->Password = EMAIL_PHPMAILER_SMTP_PASSWORD;
        
        if(EMAIL_PHPMAILER_SMTP_AUTH == 'true')
        {
          $mailer->SMTPAuth = true;
        }
        if(EMAIL_PHPMAILER_SMTP_SSL == 'true')
        {
          $mailer->SMTPSecure = "ssl";
        }
        
        $mailer->Hostname = EMAIL_PHPMAILER_SMTP_HOST;
      }
      
      $mailer->Body = stripslashes($email_text);
      $mailer->Subject = stripslashes($email_subject);
      
      if($mailer->Send())
        return true;
      
      return false;
    }
    // EOF : Phpmailer for smtp
//------------------------------------------------------------------------------------------------

7. Open the file catalog/admin/mail.php in your instalation
 Find The following text there [Line 43 and 44]:

    $mimemessage->build_message();
    while ($mail = tep_db_fetch_array($mail_query)) {
    
 And add the following code block after it :
    
//-------------------------------------------------------------------------------------------------    
    // BOF : Phpmailer for smtp
      if(EMAIL_USE_PHPMAILER == 'true')
      {
        tep_mail($mail['customers_firstname'] . ' ' . $mail['customers_lastname'], $mail['customers_email_address'], $subject, $message, '', $from);
      }
      else
      // EOF : Phpmailer for smtp
//------------------------------------------------------------------------------------------------

8. Open the file catalog/admin/includes/modules/newsletters/newsletter.php in your instalation
 Find The following text there [Line 64 and 65]:

    $mimemessage->build_message();
      while ($mail = tep_db_fetch_array($mail_query)) {
    
 And add the following code block after it :
    
//-------------------------------------------------------------------------------------------------    
    // BOF : Phpmailer for smtp
        if(EMAIL_USE_PHPMAILER == 'true')
        {
          tep_mail($mail['customers_firstname'] . ' ' . $mail['customers_lastname'], $mail['customers_email_address'], $this->title, $this->content, '', EMAIL_FROM);
        }
        else
        // EOF : Phpmailer for smtp
//------------------------------------------------------------------------------------------------

9. Open the file catalog/admin/includes/modules/newsletters/product_notification.php in your instalation
 Find The following text there [Line 208 and 209]:

    reset($audience);
      while (list($key, $value) = each ($audience)) {
    
 And add the following code block after it :
    
//-------------------------------------------------------------------------------------------------    
    // BOF : Phpmailer for smtp
        if(EMAIL_USE_PHPMAILER == 'true')
        {
          tep_mail($value['firstname'] . ' ' . $value['lastname'], $value['email_address'], $this->title, $this->content, '', EMAIL_FROM);
        }
        else
        // EOF : Phpmailer for smtp
//------------------------------------------------------------------------------------------------

SETTINGS:
-----------
You have enable the Phpmailer function in
http://yourdomain/catalog/admin/configuration.php?selected_box=configuration&gID=12

Use PHPmailer class to send email - true

contact me at sumonruet99@gmail.com if you have any query about it.