title: Sending Email with Codeigniter Taking So much time
body: <p>Here is my code in which sending an email when user signup. It takes 5 minutes or more for every mail to reaches to the user email. I do not know why email taking so much time to reach. if I am sending an email with this same function <strong>sendEmail()</strong> not with a verification code only with a simple text. Now it takes 1 minute or 1 n half minutes to reach the user email.</p>
  
  <p><strong>Sometimes it does not even send any email when I am sending the verification code at the end of the link.</strong> </p>
  
  <p>I do not know how to send the email with SMTP. I found some examples where they add their domain name to the smtp_host, email, password, which email is created with the domain. I did the same but nothing happens with my email sending. It almost same with this also whether I am using SMTP or not.</p>
  
  <p>This is my function name <strong>sendEmail(</strong>) which I have created the model to sending emails. The reason why I have created this function in the model because I have to send emails from other controllers too.
  I do not if it could be a problem in sending emails </p>
  
  <p>Please see this function where I am doing wrong. or if there is another way please tell me how to do this.or any type of suggestions will be very helpful for me.</p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>function index() {
          //my validation rules are here  
          if ($this-&gt;form_validation-&gt;run() == TRUE) {
  
              $data = $this-&gt;fetch_data_from_post();
              $user_email = $data['email'];
              $code =  random_string('unique');
              $verification_link = base_url('Home/verify/').$code;
              $subject = "Confirmation Message";
              $message = "Dear User,\n\n\nPlease click on Given below URL  to verify your Email Address ".$verification_link." \n\n Once you click on the above link then your account will be verified and you will get an opportunity to login. See you soon,Thank You...!\n";
              $email_sent = $this-&gt;Perfect_mdl-&gt;sendEmail($user_email,$subject,$message);
  
              if($email_sent != 1){
                  $flash = '&lt;div class="alert alert-danger"&gt;Opppssss Somthing went Wrong...&lt;/div&gt;';
                  $this-&gt;session-&gt;set_flashdata('user_registration',$flash);
                  redirect('Home/signup');
  
              }else{
                  $this-&gt;Perfect_mdl-&gt;_insert($data);
                  $flash = '&lt;div class="alert alert-success"&gt;You are Successfully Registered... Please Check Your Email &lt;b&gt;'.$user_email.'&lt;/b&gt; For Verification&lt;/div&gt;';
                  $this-&gt;session-&gt;set_flashdata('user_registration',$flash);
                  redirect('Home/signup');
              }
          }
  
          $data['meta_title']  = "Signup";
          $data['services_name'] = $this-&gt;Perfect_mdl-&gt;getServices_home();
          $dat['flash'] = $this-&gt;session-&gt;flashdata('user_registration');
          $this-&gt;load-&gt;view('signup',$data);
      }
  </code></pre>
  
  <p>Model:-</p>
  
  <pre><code>function sendEmail($useremail,$subject,$message) {
  
  
       $config = Array(
      'protocol' =&gt; 'smtp',
      'smtp_host' =&gt; 'smtp.mydomainname.com',
      'smtp_port' =&gt; 25,
      'smtp_user' =&gt; 'vishal@mydomainname.com', // change it to yours
      'smtp_pass' =&gt; 'vishal123456', // change it to yours
      'mailtype' =&gt; 'html',
      'charset' =&gt; 'iso-8859-1',
      'crlf' =&gt; "\r\n",
      'newline' =&gt; "\r\n",
      'wordwrap' =&gt; TRUE
      );
      $this-&gt;load-&gt;library('email', $config); 
      $this-&gt;email-&gt;from('vishal@mydomainname.com', 'Company Name');
      $this-&gt;email-&gt;to($useremail);   
  
  
      $this-&gt;email-&gt;subject($subject);
      $this-&gt;email-&gt;message($message);
      if($this-&gt;email-&gt;send()){
          return "1";
      }else{
          return "0";
      }
  }
  </code></pre>