php - PHPMailer with codeigniter is not sending mails -


i created website on windows server using codeigniter , phpmailer contact form, setup works well. after few days ago decided make website on linux server, used same codes contact form doesn't seem work.

code in controller

$email_config=array(                     "protocol"=>"smtp",                     "mailpath"=>"/usr/sbin/sendmail",                     "smtp_host"=>"mail.dnweb-solutions.com",                     "smtp_user"=>"contact@mail.dnweb-solutions.com",                     "smtp_pass"=>"****",                     "smtp_port"=>25,                 );                 $this->load->library("email");                 $this->email->initialize($email_config);                 $this->email->to("sobsdinike@gmail.com");                 $this->email->from("contact@mail.dnweb-solutions.com",$_post["fullname"]);                 $this->email->reply_to($_post["email"],$_post["fullname"]);                 $this->email->subject($_post["subject"]);                 $this->email->message($_post["message"]);                 $this->email->send(); 

code in config/email.php

<?php defined('basepath') or exit('no direct script access allowed.');  $config['useragent']        = 'phpmailer';              // mail engine     switcher: 'codeigniter' or 'phpmailer' $config['protocol']         = 'smtp';                   // 'mail', 'sendmail', or 'smtp' $config['mailpath']         = '/usr/sbin/sendmail'; $config['smtp_host']        = 'mail.dnweb-solutions.com'; $config['smtp_user']        = 'contact@mail.dnweb-solutions.com'; $config['smtp_pass']        = '****'; $config['smtp_port']        = 25; $config['smtp_timeout']     = 5;                        // (in seconds) $config['smtp_crypto']      = '';                       // '' or 'tls' or 'ssl' $config['smtp_debug']       = 0;                        // phpmailer's smtp debug info level: 0 = off, 1 = commands, 2 = commands , data, 3 = 2 plus connection status, 4 = low level data output. $config['wordwrap']         = true; $config['wrapchars']        = 76; $config['mailtype']         = 'html';                   // 'text' or 'html' $config['charset']          = 'utf-8'; $config['validate']         = true; $config['priority']         = 3;                        // 1, 2, 3, 4, 5 $config['crlf']             = "\n";                     // "\r\n" or "\n" or "\r" $config['newline']          = "\n";                     // "\r\n" or "\n" or "\r" $config['bcc_batch_mode']   = false; $config['bcc_batch_size']   = 200; $config['encoding']         = '8bit';                   // body encoding. codeigniter: '8bit' or '7bit'. phpmailer: '8bit', '7bit', 'binary', 'base64', or 'quoted-printable'. 

code on my_email.php (this incomplete 1 available on github)

<?php defined('basepath') or exit('no direct script access allowed.'); class my_email extends ci_email {  public $phpmailer;  // property has been made public testing purposes.  protected $mailer_engine = 'codeigniter'; protected $ci;  protected $_is_ci_3 = null;  protected static $protocols = array('mail', 'sendmail', 'smtp'); protected static $mailtypes = array('html', 'text'); protected static $encodings_ci = array('8bit', '7bit'); protected static $encodings_phpmailer = array('8bit', '7bit', 'binary', 'base64', 'quoted-printable');  public function __construct($config = array()) {      $this->_is_ci_3 = (bool) ((int) ci_version >= 3);      $this->ci = get_instance();     $this->ci->load->helper('email');     $this->ci->load->helper('html');      if (!is_array($config)) {         $config = array();     }      if (isset($config['useragent'])) {          $useragent = trim($config['useragent']);         $mailer_engine = strtolower($useragent);          if (strpos($mailer_engine, 'phpmailer') !== false) {             $this->mailer_engine = 'phpmailer';         } elseif(strpos($mailer_engine, 'codeigniter') !== false) {             $this->mailer_engine = 'codeigniter';         } else {             unset($config['useragent']);    // invalid setting;         }     }      if (isset($config['charset'])) {          $charset = trim($config['charset']);          if ($charset != '') {             $this->charset = $charset;             unset($config['charset']);      // don't need anymore.         }      } else {          $charset = trim(config_item('charset'));          if ($charset != '') {             $this->charset = $charset;         }     }      $this->charset = strtoupper($this->charset);      if ($this->mailer_engine == 'phpmailer') {          // if system uses class autoloading feature,         // following require statement not needed.         if (!class_exists('phpmailer', false)) {             require_once apppath.'third_party/phpmailer/phpmailerautoload.php';         }         //          $this->phpmailer = new phpmailer();         $this->phpmailer->plugindir = apppath.'third_party/phpmailer/';          $this->_copy_property_to_phpmailer('charset');     }      if (count($config) > 0) {          $this->initialize($config);      } else {          $this->_smtp_auth = ($this->smtp_user == '' , $this->smtp_pass == '') ? false : true;          if ($this->mailer_engine == 'phpmailer') {             $this->_copy_property_to_phpmailer('_smtp_auth');         }     }      $this->_safe_mode = ( ! is_php('5.4') && ini_get('safe_mode'));      log_message('info', 'my_email class initialized (engine: '.$this->mailer_engine.')'); }  /**  * define these options within $config array or  * within configuration file email.php:  * useragent  * protocol  * mailpath  * smtp_host  * smtp_user  * smtp_pass  * smtp_port  * smtp_timeout  * smtp_crypto  * set_wordwrap  * wrapchars  * mailtype  * charset  * validate  * priority  * crlf  * newline  * bcc_batch_mode  * bcc_batch_size  * encoding  */ public function initialize($config = array()) {      if (!is_array($config)) {         $config = array();     }      foreach ($config $key => $val) {          $method = 'set_'.$key;          if (method_exists($this, $method)) {              $this->$method($val);          } elseif (isset($this->$key)) {              $this->$key = $val;              if ($this->mailer_engine == 'phpmailer') {                 $this->_copy_property_to_phpmailer($key);             }         }     }      $this->clear();      $this->_smtp_auth = ($this->smtp_user == '' , $this->smtp_pass == '') ? false : true;      if ($this->mailer_engine == 'phpmailer') {         $this->_copy_property_to_phpmailer('_smtp_auth');     }      return $this; }  public function clear($clear_attachments = false) {      $clear_attachments = !empty($clear_attachments);      parent::clear($clear_attachments);      if ($this->mailer_engine == 'phpmailer') {          $this->phpmailer->clearallrecipients();         $this->phpmailer->clearreplytos();         if ($clear_attachments) {             $this->phpmailer->clearattachments();         }          $this->phpmailer->clearcustomheaders();          $this->phpmailer->subject = '';         $this->phpmailer->body = '';         $this->phpmailer->altbody = '';     }      return $this; }  public function set_protocol($protocol = 'mail') {      $protocol = trim(strtolower($protocol));      $this->protocol = in_array($protocol, self::$protocols) ? $protocol : 'mail';      if ($this->mailer_engine == 'phpmailer') {          switch ($this->protocol) {              case 'mail':                 $this->phpmailer->ismail();                 break;              case 'sendmail':                 $this->phpmailer->issendmail();                 break;              case 'smtp':                 $this->phpmailer->issmtp();                 break;         }     }      return $this; }  public function set_smtp_crypto($smtp_crypto = '') {      $smtp_crypto = trim(strtolower($smtp_crypto));      if ($smtp_crypto != 'tls' && $smtp_crypto != 'ssl') {         $smtp_crypto = '';     }      $this->smtp_crypto = $smtp_crypto;      if ($this->mailer_engine == 'phpmailer') {         $this->phpmailer->smtpsecure = $smtp_crypto;     }      return $this; }  public function set_wordwrap($wordwrap = true) {      $this->wordwrap = !empty($wordwrap);      if (!$this->wordwrap) {          if ($this->mailer_engine == 'phpmailer') {             $this->phpmailer->wordwrap = 0;         }     }      return $this; }  public function set_mailtype($type = 'text') {      $type = trim(strtolower($type));      $this->mailtype = in_array($type, self::$mailtypes) ? $type : 'text';      if ($this->mailer_engine == 'phpmailer') {         $this->phpmailer->ishtml($this->mailtype == 'html');     }      return $this; }  public function set_priority($n = 3) {      $this->priority = preg_match('/^[1-5]$/', $n) ? (int) $n : 3;      if ($this->mailer_engine == 'phpmailer') {         $this->phpmailer->priority = $this->priority;     }      return $this; }  public function valid_email($email) {      return valid_email($email); }  public function from($from, $name = '', $return_path = null) {      $from = (string) $from;     $name = (string) $name;     $return_path = (string) $return_path;      if ($this->mailer_engine == 'phpmailer') {          if (preg_match( '/\<(.*)\>/', $from, $match)) {             $from = $match['1'];         }          if ($this->validate) {              $this->validate_email($this->_str_to_array($from));              if ($return_path) {                 $this->validate_email($this->_str_to_array($return_path));             }         }          $this->phpmailer->setfrom($from, $name, 0);          if (!$return_path) {             $return_path = $from;         }          $this->phpmailer->sender = $return_path;      } else {          if ($this->_is_ci_3) {             parent::from($from, $name, $return_path);         } else {             parent::from($from, $name);         }     }      return $this; }  public function reply_to($replyto, $name = '') {      $replyto = (string) $replyto;     $name = (string) $name;      if ($this->mailer_engine == 'phpmailer') {          if (preg_match( '/\<(.*)\>/', $replyto, $match)) {             $replyto = $match['1'];         }          if ($this->validate) {             $this->validate_email($this->_str_to_array($replyto));         }          if ($name == '') {             $name = $replyto;         }          $this->phpmailer->addreplyto($replyto, $name);          $this->_replyto_flag = true;      } else {          parent::reply_to($replyto, $name);     }      return $this; }  public function to($to) {      if ($this->mailer_engine == 'phpmailer') {          $to = $this->_str_to_array($to);         $names = $this->_extract_name($to);         $to = $this->clean_email($to);          if ($this->validate) {             $this->validate_email($to);         }          reset($names);          foreach ($to $address) {              list($key, $name) = each($names);             $this->phpmailer->addaddress($address, $name);         }      } else {          parent::to($to);     }      return $this; }  public function cc($cc) {      if ($this->mailer_engine == 'phpmailer') {          $cc = $this->_str_to_array($cc);         $names = $this->_extract_name($cc);         $cc = $this->clean_email($cc);          if ($this->validate) {             $this->validate_email($cc);         }          reset($names);          foreach ($cc $address) {              list($key, $name) = each($names);             $this->phpmailer->addcc($address, $name);         }      } else {          parent::cc($cc);     }      return $this; }  public function bcc($bcc, $limit = '') {      if ($this->mailer_engine == 'phpmailer') {          $bcc = $this->_str_to_array($bcc);         $names = $this->_extract_name($bcc);         $bcc = $this->clean_email($bcc);          if ($this->validate) {             $this->validate_email($bcc);         }          reset($names);          foreach ($bcc $address) {              list($key, $name) = each($names);             $this->phpmailer->addbcc($address, $name);         }      } else {          parent::bcc($bcc, $limit);     }      return $this; }  public function subject($subject) {      $subject = (string) $subject;      if ($this->mailer_engine == 'phpmailer') {         $this->phpmailer->subject = (string) $subject;      } else {          parent::subject($subject);     }      return $this; }  public function message($body) {      $body = (string) $body;      if ($this->mailer_engine == 'phpmailer') {          $this->phpmailer->body = $body;     }      parent::message($body);      return $this; }  // modified ivan tcholakov, 16-jan-2014. //public function attach($file, $disposition = '', $newname = null, $mime = '') { public function attach($file, $disposition = '', $newname = null, $mime = '', $embedded_image = false) { //      $file = (string) $file;      $disposition = (string) $disposition;      if ($disposition == '') {         $disposition ='attachment';     }      if ($this->mailer_engine == 'phpmailer') {          $newname = (string) $newname;         $mime = (string) $mime;          if ($mime == '') {              if (strpos($file, '://') === false && ! file_exists($file)) {                  $this->_set_error_message('lang:email_attachment_missing', $file);                 // modified ivan tcholakov, 14-jan-2014.                 //return false;                 return $this;                 //             }              if (!$fp = @fopen($file, fopen_read)) {                  $this->_set_error_message('lang:email_attachment_unreadable', $file);                 // modified ivan tcholakov, 14-jan-2014.                 //return false;                 return $this;                 //             }              $file_content = stream_get_contents($fp);             $mime = $this->_mime_types(pathinfo($file, pathinfo_extension));             fclose($fp);              $newname = basename($file);          } else {              $file_content =& $file; // buffered file.             // added ivan tcholakov, 14-jan-2014.             $file = $newname;             //         }          $this->_attachments[] = array(             'name' => array($file, $newname),             'disposition' => $disposition,             'type' => $mime,         );          if (empty($embedded_image)) {              $this->phpmailer->addstringattachment($file_content, $newname, 'base64', $mime, $disposition);          } else {              $cid = $this->attachment_cid($file);             $this->phpmailer->addstringembeddedimage($file_content, $cid, $newname, 'base64', $mime, $disposition);         }      } else {          if ($this->_is_ci_3) {             parent::attach($file, $disposition, $newname, $mime);         } else {             parent::attach($file, $disposition);         }     }      return $this; }  public function attachment_cid($filename) {      if ($this->mailer_engine == 'phpmailer') {          ($i = 0, $c = count($this->_attachments); $i < $c; $i++) {              if ($this->_attachments[$i]['name'][0] === $filename) {                  $this->_attachments[$i]['cid'] = uniqid(basename($this->_attachments[$i]['name'][0]).'@');                 return $this->_attachments[$i]['cid'];             }         }      } elseif ($this->_is_ci_3) {          return parent::attachment_cid($filename);     }      return false; }  // added ivan tcholakov, 16-jan-2014. public function get_attachment_cid($filename) {      ($i = 0, $c = count($this->_attachments); $i < $c; $i++) {          if ($this->_attachments[$i]['name'][0] === $filename) {             return empty($this->_attachments[$i]['cid']) ? false : $this->_attachments[$i]['cid'];         }     }      return false; } //  public function send($auto_clear = true) {      $auto_clear = !empty($auto_clear);      if ($this->mailer_engine == 'phpmailer') {          if ($this->mailtype == 'html') {             $this->phpmailer->altbody = $this->_get_alt_message();         }          $result = (bool) $this->phpmailer->send();          if ($result) {              $this->_set_error_message('lang:email_sent', $this->_get_protocol());              if ($auto_clear) {                 $this->clear();             }          } else {              $this->_set_error_message($this->phpmailer->errorinfo);         }      } else {          if ($this->_is_ci_3) {             $result = parent::send($auto_clear);         } else {             $result = parent::send();         }     }      return $result; }   // custom methods ----------------------------------------------------------  // setting explicitly body encoding. // see https://github.com/ivantcholakov/codeigniter-phpmailer/issues/3 public function set_encoding($encoding) {      if ($this->mailer_engine == 'phpmailer') {          if (!in_array($encoding, self::$encodings_phpmailer)) {             $encoding = '8bit';         }          $this->phpmailer->encoding = $encoding;      } elseif (!in_array($encoding, self::$encodings_ci)) {          $encoding = '8bit';     }      $this->_encoding = $encoding;      return $this; }  // phpmailer's smtp debug info level // 0 = off, 1 = commands, 2 = commands , data, 3 = 2 plus connection status, 4 = low level data output. public function set_smtp_debug($level) {      $level = (int) $level;      if ($level < 0) {         $level = 0;     }      if ($this->mailer_engine == 'phpmailer') {         $this->phpmailer->smtpdebug = $level;     }      return $this; } 


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -