title: PHPMailer with codeigniter is not sending mails
body: <p>I created a website on a windows server using codeigniter and phpmailer for its contact form, this setup works well. After a few days ago I decided to make another website on a Linux server, I used almost the same codes but my contact form doesn't seem to work.</p>
  
  <p>Code in my controller</p>
  
  <pre><code>$email_config=array(
                      "protocol"=&gt;"smtp",
                      "mailpath"=&gt;"/usr/sbin/sendmail",
                      "smtp_host"=&gt;"mail.dnweb-solutions.com",
                      "smtp_user"=&gt;"contact@mail.dnweb-solutions.com",
                      "smtp_pass"=&gt;"****",
                      "smtp_port"=&gt;25,
                  );
                  $this-&gt;load-&gt;library("email");
                  $this-&gt;email-&gt;initialize($email_config);
                  $this-&gt;email-&gt;to("sobsdinike@gmail.com");
                  $this-&gt;email-&gt;from("contact@mail.dnweb-solutions.com",$_POST["fullname"]);
                  $this-&gt;email-&gt;reply_to($_POST["email"],$_POST["fullname"]);
                  $this-&gt;email-&gt;subject($_POST["subject"]);
                  $this-&gt;email-&gt;message($_POST["message"]);
                  $this-&gt;email-&gt;send();
  </code></pre>
  
  <p>Code in my config/email.php</p>
  
  <pre><code>&lt;?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 and data, 3 = as 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';                   // The body encoding. For CodeIgniter: '8bit' or '7bit'. For PHPMailer: '8bit', '7bit', 'binary', 'base64', or 'quoted-printable'.
  </code></pre>
  
  <p>Code on MY_Email.php (this is incomplete but this is the one available on github)</p>
  
  <pre><code>&lt;?php defined('BASEPATH') OR exit('No direct script access allowed.');
  class MY_Email extends CI_Email {
  
  public $phpmailer;  // This property has been made public for 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-&gt;_is_ci_3 = (bool) ((int) CI_VERSION &gt;= 3);
  
      $this-&gt;CI = get_instance();
      $this-&gt;CI-&gt;load-&gt;helper('email');
      $this-&gt;CI-&gt;load-&gt;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-&gt;mailer_engine = 'phpmailer';
          } elseif(strpos($mailer_engine, 'codeigniter') !== false) {
              $this-&gt;mailer_engine = 'codeigniter';
          } else {
              unset($config['useragent']);    // An invalid setting;
          }
      }
  
      if (isset($config['charset'])) {
  
          $charset = trim($config['charset']);
  
          if ($charset != '') {
              $this-&gt;charset = $charset;
              unset($config['charset']);      // We don't need this anymore.
          }
  
      } else {
  
          $charset = trim(config_item('charset'));
  
          if ($charset != '') {
              $this-&gt;charset = $charset;
          }
      }
  
      $this-&gt;charset = strtoupper($this-&gt;charset);
  
      if ($this-&gt;mailer_engine == 'phpmailer') {
  
          // If your system uses class autoloading feature,
          // then the following require statement would not be needed.
          if (!class_exists('PHPMailer', false)) {
              require_once APPPATH.'third_party/phpmailer/PHPMailerAutoload.php';
          }
          //
  
          $this-&gt;phpmailer = new PHPMailer();
          $this-&gt;phpmailer-&gt;PluginDir = APPPATH.'third_party/phpmailer/';
  
          $this-&gt;_copy_property_to_phpmailer('charset');
      }
  
      if (count($config) &gt; 0) {
  
          $this-&gt;initialize($config);
  
      } else {
  
          $this-&gt;_smtp_auth = ($this-&gt;smtp_user == '' AND $this-&gt;smtp_pass == '') ? FALSE : TRUE;
  
          if ($this-&gt;mailer_engine == 'phpmailer') {
              $this-&gt;_copy_property_to_phpmailer('_smtp_auth');
          }
      }
  
      $this-&gt;_safe_mode = ( ! is_php('5.4') &amp;&amp; ini_get('safe_mode'));
  
      log_message('info', 'MY_Email Class Initialized (Engine: '.$this-&gt;mailer_engine.')');
  }
  
  /**
   * Define these options within the $config array or
   * within the 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 as $key =&gt; $val) {
  
          $method = 'set_'.$key;
  
          if (method_exists($this, $method)) {
  
              $this-&gt;$method($val);
  
          } elseif (isset($this-&gt;$key)) {
  
              $this-&gt;$key = $val;
  
              if ($this-&gt;mailer_engine == 'phpmailer') {
                  $this-&gt;_copy_property_to_phpmailer($key);
              }
          }
      }
  
      $this-&gt;clear();
  
      $this-&gt;_smtp_auth = ($this-&gt;smtp_user == '' AND $this-&gt;smtp_pass == '') ? FALSE : TRUE;
  
      if ($this-&gt;mailer_engine == 'phpmailer') {
          $this-&gt;_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-&gt;mailer_engine == 'phpmailer') {
  
          $this-&gt;phpmailer-&gt;clearAllRecipients();
          $this-&gt;phpmailer-&gt;clearReplyTos();
          if ($clear_attachments) {
              $this-&gt;phpmailer-&gt;clearAttachments();
          }
  
          $this-&gt;phpmailer-&gt;clearCustomHeaders();
  
          $this-&gt;phpmailer-&gt;Subject = '';
          $this-&gt;phpmailer-&gt;Body = '';
          $this-&gt;phpmailer-&gt;AltBody = '';
      }
  
      return $this;
  }
  
  public function set_protocol($protocol = 'mail') {
  
      $protocol = trim(strtolower($protocol));
  
      $this-&gt;protocol = in_array($protocol, self::$protocols) ? $protocol : 'mail';
  
      if ($this-&gt;mailer_engine == 'phpmailer') {
  
          switch ($this-&gt;protocol) {
  
              case 'mail':
                  $this-&gt;phpmailer-&gt;isMail();
                  break;
  
              case 'sendmail':
                  $this-&gt;phpmailer-&gt;isSendmail();
                  break;
  
              case 'smtp':
                  $this-&gt;phpmailer-&gt;isSMTP();
                  break;
          }
      }
  
      return $this;
  }
  
  public function set_smtp_crypto($smtp_crypto = '') {
  
      $smtp_crypto = trim(strtolower($smtp_crypto));
  
      if ($smtp_crypto != 'tls' &amp;&amp; $smtp_crypto != 'ssl') {
          $smtp_crypto = '';
      }
  
      $this-&gt;smtp_crypto = $smtp_crypto;
  
      if ($this-&gt;mailer_engine == 'phpmailer') {
          $this-&gt;phpmailer-&gt;SMTPSecure = $smtp_crypto;
      }
  
      return $this;
  }
  
  public function set_wordwrap($wordwrap = TRUE) {
  
      $this-&gt;wordwrap = !empty($wordwrap);
  
      if (!$this-&gt;wordwrap) {
  
          if ($this-&gt;mailer_engine == 'phpmailer') {
              $this-&gt;phpmailer-&gt;WordWrap = 0;
          }
      }
  
      return $this;
  }
  
  public function set_mailtype($type = 'text') {
  
      $type = trim(strtolower($type));
  
      $this-&gt;mailtype = in_array($type, self::$mailtypes) ? $type : 'text';
  
      if ($this-&gt;mailer_engine == 'phpmailer') {
          $this-&gt;phpmailer-&gt;isHTML($this-&gt;mailtype == 'html');
      }
  
      return $this;
  }
  
  public function set_priority($n = 3) {
  
      $this-&gt;priority = preg_match('/^[1-5]$/', $n) ? (int) $n : 3;
  
      if ($this-&gt;mailer_engine == 'phpmailer') {
          $this-&gt;phpmailer-&gt;Priority = $this-&gt;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-&gt;mailer_engine == 'phpmailer') {
  
          if (preg_match( '/\&lt;(.*)\&gt;/', $from, $match)) {
              $from = $match['1'];
          }
  
          if ($this-&gt;validate) {
  
              $this-&gt;validate_email($this-&gt;_str_to_array($from));
  
              if ($return_path) {
                  $this-&gt;validate_email($this-&gt;_str_to_array($return_path));
              }
          }
  
          $this-&gt;phpmailer-&gt;setFrom($from, $name, 0);
  
          if (!$return_path) {
              $return_path = $from;
          }
  
          $this-&gt;phpmailer-&gt;Sender = $return_path;
  
      } else {
  
          if ($this-&gt;_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-&gt;mailer_engine == 'phpmailer') {
  
          if (preg_match( '/\&lt;(.*)\&gt;/', $replyto, $match)) {
              $replyto = $match['1'];
          }
  
          if ($this-&gt;validate) {
              $this-&gt;validate_email($this-&gt;_str_to_array($replyto));
          }
  
          if ($name == '') {
              $name = $replyto;
          }
  
          $this-&gt;phpmailer-&gt;addReplyTo($replyto, $name);
  
          $this-&gt;_replyto_flag = TRUE;
  
      } else {
  
          parent::reply_to($replyto, $name);
      }
  
      return $this;
  }
  
  public function to($to) {
  
      if ($this-&gt;mailer_engine == 'phpmailer') {
  
          $to = $this-&gt;_str_to_array($to);
          $names = $this-&gt;_extract_name($to);
          $to = $this-&gt;clean_email($to);
  
          if ($this-&gt;validate) {
              $this-&gt;validate_email($to);
          }
  
          reset($names);
  
          foreach ($to as $address) {
  
              list($key, $name) = each($names);
              $this-&gt;phpmailer-&gt;addAddress($address, $name);
          }
  
      } else {
  
          parent::to($to);
      }
  
      return $this;
  }
  
  public function cc($cc) {
  
      if ($this-&gt;mailer_engine == 'phpmailer') {
  
          $cc = $this-&gt;_str_to_array($cc);
          $names = $this-&gt;_extract_name($cc);
          $cc = $this-&gt;clean_email($cc);
  
          if ($this-&gt;validate) {
              $this-&gt;validate_email($cc);
          }
  
          reset($names);
  
          foreach ($cc as $address) {
  
              list($key, $name) = each($names);
              $this-&gt;phpmailer-&gt;addCC($address, $name);
          }
  
      } else {
  
          parent::cc($cc);
      }
  
      return $this;
  }
  
  public function bcc($bcc, $limit = '') {
  
      if ($this-&gt;mailer_engine == 'phpmailer') {
  
          $bcc = $this-&gt;_str_to_array($bcc);
          $names = $this-&gt;_extract_name($bcc);
          $bcc = $this-&gt;clean_email($bcc);
  
          if ($this-&gt;validate) {
              $this-&gt;validate_email($bcc);
          }
  
          reset($names);
  
          foreach ($bcc as $address) {
  
              list($key, $name) = each($names);
              $this-&gt;phpmailer-&gt;addBCC($address, $name);
          }
  
      } else {
  
          parent::bcc($bcc, $limit);
      }
  
      return $this;
  }
  
  public function subject($subject) {
  
      $subject = (string) $subject;
  
      if ($this-&gt;mailer_engine == 'phpmailer') {
  
         $this-&gt;phpmailer-&gt;Subject = (string) $subject;
  
      } else {
  
          parent::subject($subject);
      }
  
      return $this;
  }
  
  public function message($body) {
  
      $body = (string) $body;
  
      if ($this-&gt;mailer_engine == 'phpmailer') {
  
          $this-&gt;phpmailer-&gt;Body = $body;
      }
  
      parent::message($body);
  
      return $this;
  }
  
  // Modified by 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-&gt;mailer_engine == 'phpmailer') {
  
          $newname = (string) $newname;
          $mime = (string) $mime;
  
          if ($mime == '') {
  
              if (strpos($file, '://') === FALSE &amp;&amp; ! file_exists($file)) {
  
                  $this-&gt;_set_error_message('lang:email_attachment_missing', $file);
                  // Modified by Ivan Tcholakov, 14-JAN-2014.
                  //return FALSE;
                  return $this;
                  //
              }
  
              if (!$fp = @fopen($file, FOPEN_READ)) {
  
                  $this-&gt;_set_error_message('lang:email_attachment_unreadable', $file);
                  // Modified by Ivan Tcholakov, 14-JAN-2014.
                  //return FALSE;
                  return $this;
                  //
              }
  
              $file_content = stream_get_contents($fp);
              $mime = $this-&gt;_mime_types(pathinfo($file, PATHINFO_EXTENSION));
              fclose($fp);
  
              $newname = basename($file);
  
          } else {
  
              $file_content =&amp; $file; // Buffered file.
              // Added by Ivan Tcholakov, 14-JAN-2014.
              $file = $newname;
              //
          }
  
          $this-&gt;_attachments[] = array(
              'name' =&gt; array($file, $newname),
              'disposition' =&gt; $disposition,
              'type' =&gt; $mime,
          );
  
          if (empty($embedded_image)) {
  
              $this-&gt;phpmailer-&gt;addStringAttachment($file_content, $newname, 'base64', $mime, $disposition);
  
          } else {
  
              $cid = $this-&gt;attachment_cid($file);
              $this-&gt;phpmailer-&gt;addStringEmbeddedImage($file_content, $cid, $newname, 'base64', $mime, $disposition);
          }
  
      } else {
  
          if ($this-&gt;_is_ci_3) {
              parent::attach($file, $disposition, $newname, $mime);
          } else {
              parent::attach($file, $disposition);
          }
      }
  
      return $this;
  }
  
  public function attachment_cid($filename) {
  
      if ($this-&gt;mailer_engine == 'phpmailer') {
  
          for ($i = 0, $c = count($this-&gt;_attachments); $i &lt; $c; $i++) {
  
              if ($this-&gt;_attachments[$i]['name'][0] === $filename) {
  
                  $this-&gt;_attachments[$i]['cid'] = uniqid(basename($this-&gt;_attachments[$i]['name'][0]).'@');
                  return $this-&gt;_attachments[$i]['cid'];
              }
          }
  
      } elseif ($this-&gt;_is_ci_3) {
  
          return parent::attachment_cid($filename);
      }
  
      return FALSE;
  }
  
  // Added by Ivan Tcholakov, 16-JAN-2014.
  public function get_attachment_cid($filename) {
  
      for ($i = 0, $c = count($this-&gt;_attachments); $i &lt; $c; $i++) {
  
          if ($this-&gt;_attachments[$i]['name'][0] === $filename) {
              return empty($this-&gt;_attachments[$i]['cid']) ? FALSE : $this-&gt;_attachments[$i]['cid'];
          }
      }
  
      return FALSE;
  }
  //
  
  public function send($auto_clear = true) {
  
      $auto_clear = !empty($auto_clear);
  
      if ($this-&gt;mailer_engine == 'phpmailer') {
  
          if ($this-&gt;mailtype == 'html') {
              $this-&gt;phpmailer-&gt;AltBody = $this-&gt;_get_alt_message();
          }
  
          $result = (bool) $this-&gt;phpmailer-&gt;send();
  
          if ($result) {
  
              $this-&gt;_set_error_message('lang:email_sent', $this-&gt;_get_protocol());
  
              if ($auto_clear) {
                  $this-&gt;clear();
              }
  
          } else {
  
              $this-&gt;_set_error_message($this-&gt;phpmailer-&gt;ErrorInfo);
          }
  
      } else {
  
          if ($this-&gt;_is_ci_3) {
              $result = parent::send($auto_clear);
          } else {
              $result = parent::send();
          }
      }
  
      return $result;
  }
  
  
  // Custom methods ----------------------------------------------------------
  
  // Setting explicitly the body encoding.
  // See https://github.com/ivantcholakov/codeigniter-phpmailer/issues/3
  public function set_encoding($encoding) {
  
      if ($this-&gt;mailer_engine == 'phpmailer') {
  
          if (!in_array($encoding, self::$encodings_phpmailer)) {
              $encoding = '8bit';
          }
  
          $this-&gt;phpmailer-&gt;Encoding = $encoding;
  
      } elseif (!in_array($encoding, self::$encodings_ci)) {
  
          $encoding = '8bit';
      }
  
      $this-&gt;_encoding = $encoding;
  
      return $this;
  }
  
  // PHPMailer's SMTP debug info level
  // 0 = off, 1 = commands, 2 = commands and data, 3 = as 2 plus connection status, 4 = low level data output.
  public function set_smtp_debug($level) {
  
      $level = (int) $level;
  
      if ($level &lt; 0) {
          $level = 0;
      }
  
      if ($this-&gt;mailer_engine == 'phpmailer') {
          $this-&gt;phpmailer-&gt;SMTPDebug = $level;
      }
  
      return $this;
  }
  </code></pre>