title: Contact us email function in codeigniter is not working
body: <p>I made an contact form in codeigniter so users can contact me but when I try to send the email nothing is send. I don't know why it happens. Also I know This has been asked before but I only want to know if there's something wrong with my code.</p>
  
  <p>This is my controller:</p>
  
  <pre><code>    &lt;?php
  class Contactform extends CI_Controller
  {
      public function __construct()
      {
          parent::__construct();
          $this-&gt;load-&gt;helper(array('form','url'));
          $this-&gt;load-&gt;library(array('session', 'form_validation', 'email'));
      }
  
      function index()
      {
        //set validation rules
        //$this-&gt;form_validation-&gt;set_rules('name', 'Name', 'trim|required|xss_clean|callback_alpha_space_only');
          //$this-&gt;form_validation-&gt;set_rules('email', 'Email ID', 'trim|required|valid_email');
         //$this-&gt;form_validation-&gt;set_rules('subject', 'Subject', 'trim|required|xss_clean');
         //$this-&gt;form_validation-&gt;set_rules('message', 'Message', 'trim|required|xss_clean');
  
          //run validation on form input
          if ($this-&gt;form_validation-&gt;run() == FALSE)
          {
              //validation fails
              $this-&gt;load-&gt;view('contact_form_view');
          }
          else
          {
              //get the form data
              $name = $this-&gt;input-&gt;post('name');
              $from_email = $this-&gt;input-&gt;post('email');
              $subject = $this-&gt;input-&gt;post('subject');
              $message = $this-&gt;input-&gt;post('message');
  
              //naar welk email je het wilt sturen
              $to_email = 'ferran1004@gmail.com';
  
  
  
              //send mail
              $this-&gt;load-&gt;library('email', $config);
              $this-&gt;email-&gt;from($from_email, $name);
              $this-&gt;email-&gt;to($to_email);
              $this-&gt;email-&gt;subject($subject);
              $this-&gt;email-&gt;message($message);
               if ($this-&gt;email-&gt;send() == TRUE)
              {
                  // email sent
                  $this-&gt;session-&gt;set_flashdata('msg','&lt;div class="alert alert-success text-center"&gt;Your mail has been sent successfully!&lt;/div&gt;');
                  redirect('contactform/index');
              }
              else
              {
                  //error
                  $this-&gt;session-&gt;set_flashdata('msg','&lt;div class="alert alert-danger text-center"&gt;There is error in sending mail! Please try again later&lt;/div&gt;');
                  redirect('contactform/index');
              }
          }
      }
  
      //Alleen alfabet letters en spaties code
      function alpha_space_only($str)
     {
          if (!preg_match("/^[a-zA-Z ]+$/",$str))
          {
              $this-&gt;form_validation-&gt;set_message('alpha_space_only', 'The %s field must contain only alphabets and space');
              return FALSE;
          }
          else
          {
             return TRUE;
          }
      } 
  }
  ?&gt;
  </code></pre>
  
  <p>This is my view:</p>
  
  <pre><code>&lt;div class="container"&gt;
      &lt;div class="row"&gt;
          &lt;div class="col-md-6 col-md-offset-3 well"&gt;
              &lt;?php $attributes = array("class" =&gt; "form-horizontal", "name" =&gt; "Contactform");
              echo form_open("Contactform/index", $attributes);?&gt;
              &lt;fieldset&gt;
              &lt;legend&gt;Contact Form&lt;/legend&gt;
              &lt;div class="form-group"&gt;
                  &lt;div class="col-md-12"&gt;
                      &lt;label for="name" class="control-label"&gt;Name&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class="col-md-12"&gt;
                      &lt;input class="form-control" name="name" placeholder="Your Full Name" type="text" value="&lt;?php echo set_value('name'); ?&gt;" /&gt;
                      &lt;span class="text-danger"&gt;&lt;?php echo form_error('name'); ?&gt;&lt;/span&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
              &lt;div class="form-group"&gt;
                  &lt;div class="col-md-12"&gt;
                      &lt;label for="email" class="control-label"&gt;Email ID&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class="col-md-12"&gt;
                      &lt;input class="form-control" name="email" placeholder="Your Email ID" type="text" value="&lt;?php echo set_value('email'); ?&gt;" /&gt;
                      &lt;span class="text-danger"&gt;&lt;?php echo form_error('email'); ?&gt;&lt;/span&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
              &lt;div class="form-group"&gt;
                  &lt;div class="col-md-12"&gt;
                      &lt;label for="subject" class="control-label"&gt;Subject&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class="col-md-12"&gt;
                      &lt;input class="form-control" name="subject" placeholder="Your Subject" type="text" value="&lt;?php echo set_value('subject'); ?&gt;" /&gt;
                      &lt;span class="text-danger"&gt;&lt;?php echo form_error('subject'); ?&gt;&lt;/span&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
              &lt;div class="form-group"&gt;
                  &lt;div class="col-md-12"&gt;
                      &lt;label for="message" class="control-label"&gt;Message&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class="col-md-12"&gt;
                      &lt;textarea class="form-control" name="message" rows="4" placeholder="Your Message"&gt;&lt;?php echo set_value('message'); ?&gt;&lt;/textarea&gt;
                      &lt;span class="text-danger"&gt;&lt;?php echo form_error('message'); ?&gt;&lt;/span&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
              &lt;div class="form-group"&gt;
                  &lt;div class="col-md-12"&gt;
                      &lt;input name="submit" type="submit" class="btn btn-primary" value="Send" /&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;/fieldset&gt;
              &lt;?php echo form_close(); ?&gt;
              &lt;?php echo $this-&gt;session-&gt;flashdata('msg'); ?&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This is my email.php file in my config folder:</p>
  
  <pre><code>&lt;?php
      $config['protocol'] = 'smtp';
      $config['smtp_host'] = 'ssl://smtp.gmail.com'; //change this
      $config['smtp_port'] = '465';
      $config['smtp_user'] = 'xxxxx@gmail.com'; //change this
      $config['smtp_pass'] = 'xxxxxxx'; //change this
      $config['mailtype'] = 'html';
      $config['charset'] = 'iso-8859-1';
      $config['wordwrap'] = TRUE;
      $config['newline'] = "\r\n"; //use double quotes to comply with RFC 822 standard
  
  ?&gt;
  </code></pre>
  
  <p>When I click on send, no email is send.</p>