2015-12-21 21 views
0
function registration_ajax(){ 
     $this->load->library('form_validation'); 
     $this->form_validation->set_rules('email','email','required|is_unique[register.email]'); 

     if($this->form_validation->run() == FALSE){ 
      $data = '{"status":"false","message":"Email already exists"}'; 
     } 
     else 
     { 

      $email=$this->input->post('email'); 
      $data= array(
       'email'=>$email 
      ); 

      $last_id = $this->model->registeration($data);    
      if ($last_id>0) { 
       $this->send_email($email); 
       $data = '{"status":"true","message":"Email Created successfully"}'; 
      } 

     } 
     echo $data; 
    } 

    public function send_email($to='',$username="",$from='[email protected]') 
     ///function send_mail() 
    { 

     $this->load->library('encrypt'); 
     $toEmail = $this->encrypt->encode($to); 

     $toEmail = str_replace('/','forwardSlash',$toEmail); 
     $toEmail = str_replace('=','equalSign',$toEmail); 
     $toEmail = str_replace('+', 'plusSign', $toEmail); 

     $this->load->library('email'); 
     $config['protocol']  = 'smtp'; 
       $config['smtp_host'] = 'sadasds';//pust mail.com.pk 
       $config['smtp_port'] = '25334'; 
       $config['smtp_user'] = 'example'; 
       $config['smtp_pass'] = 'example1'; 
       $config['charset']  = 'utf-8'; 
       $config['mailtype']  = 'html'; 
       $config['validation'] = FALSE; // bool whether to validate email or not   

       $this->email->initialize($config); 
       $message = '<h1 align="center">Hellow</h1>'; 
       $message = '<html><body style="color:#000; font-weight:normal; font-size:13/14px;"><p style="color:#000;">Hi!</p>'; 
       $message .= '<table rules="all">'; 

       $message .= "<p>Congratulations! You have almost completed your registration on Electronic Mall.<br><br>Click on link here to confirm your email address<br> <a href=\"http://10.10.10.44/Freeclassified/index.php/controller/register_second/$toEmail\">10.10.10.44</a><br><br>Thank you for joining us and becoming part of world's largest local classified sites.In our website, you can enjoy simple ad posting, easy searching and endless local listing for products.We appreciate you for choosing us in online market place.<br> Wishing you alot of success on your classified journey.Get started now!<br><br></p>"; 
       $message .= "<p>Regards,<br>The Electronic Mall Team</p>"; 

       $message .= "</table>"; 
       $message .= "</body></html>"; 
       $this->email->from($from); 
       $this->email->to($to); 
       $this->email->subject('Confirmation Email'); 
       $this->email->message($message); 
       if(!$this->email->send()){ 
        echo $this->email->print_debugger(); 
        die(); 
       }else{ 

       } 


      } 


////ajx code 
////////////////// 


<script> 
    $(document).ready(function(){ 
    $('#registration_form').on('submit',function(e){ 
     var email = $('#email').val(); 

     $.ajax({ 

     url: "<?=base_url('controller/registration_ajax')?>", 
     // url: "<?=base_url('controller/register')?>", 
     type: "POST", 
     datatype: "JSON", 
     data: {email: email}, 
     success: function(res){ 
      var data = $.parseJSON(res); 
      var status = data.status; 
      var message = data.message; 
      if(status == 'true'){ 
      /// $('#myModal').modal('hide'); 
      $('#message_sent').html(message); 
      } 
      else{ 
      $('#message').html(message); 
      } 
     } 
     }); 
     e.preventDefault(); 
    }); 
    }); 
</script> 

我想要的電子郵件發送成功後,然後應顯示顯示電子郵件後一代消息,或者利用AJAX

$data = '{"status":"true","message":"Email Created successfully"}'; 

當我評論的郵件發送功能,那麼它顯示成功的消息,此消息發送,我希望在發送電子郵件後顯示該消息。

+3

Ø梅里BHAI yahan面值apnay個人密碼墊德雅卡羅,問題的主要SY刪除煤油APNA電子郵件KA密碼! – Ahsan

+0

謝謝@tashreef分享密碼... ab tashreef rkh k betho ...好心編輯 – devpro

+1

thanx提醒我這個。 – tashreef

回答

0

你有沒有試過從你的send_email函數返回一個值?

if(!$this->email->send()){ 

    return 'success'; 
}else{ 
    $this->session->set_flashdata('message', 'To complete registration, click the link in email we just send you at [email protected]'); 
    redirect('controller/login_register','refresh'); 

    die(); 

}在

則:

if ($last_id>0) { 
    $res = $this->send_email($email); 
    if($res === 'success'){ 
     $data = '{"status":"true","message":"Email Created successfully"}'; 
    } 

} 
+0

不,我想如果生成電子郵件,它會告訴我成功的消息,但消息發出,它不會給我成功的消息。我不想回報任何價值。 – tashreef

+0

@tashreef返回值實際上是成功的迴應。 – Ahsan

+0

親愛的我在pupop模型中展示了這個成功消息,並且還從彈出模型中插入郵件。如何在poup模型中沒有響應$ data ='{「status」:「true」,「message」:「Email Created successfully」}'; }。錯誤信息是正確的,但沒有成功的郵件後,當我評論電子郵件功能的電子郵件發送,然後顯示成功消息,這就是爲什麼。然後在數據庫中插入記錄但不生成電子郵件。 – tashreef

相關問題