2017-06-23 7 views
1

私はcodeigniterで登録ページを作成しますが、すべてが良いですが、登録をクリックするとデータベースにすべてのデータが挿入されますが、エラー:Codeigniterがエラーをスローして、ユーザに確認メールを送信しない

THE FOLLOWING SMTP ERROR WAS ENCOUNTERED: 99 CANNOT ASSIGN REQUESTED ADDRESS UNABLE TO SEND EMAIL USING PHP SMTP. YOUR SERVER MIGHT NOT BE CONFIGURED TO SEND MAIL USING THIS METHOD.

DATE: FRI, 23 JUN 2017 16:15:55 +0300 FROM: "WTF" RETURN-PATH: TO: [email protected] SUBJECT: =?UTF-8?Q?VERIFY=20YOUR=20EMAIL=20AD?==?UTF-8?Q?DRESS?= REPLY-TO: USER-AGENT: CODEIGNITER X-SENDER: [email protected] X-MAILER: CODEIGNITER X-PRIORITY: 3 (NORMAL) MESSAGE-ID: <[email protected]> MIME-VERSION: 1.0

は、ここに私のコントローラです:

<?php 
class User extends CI_Controller 
{ 
    public function __construct() 
    { 
     parent::__construct(); 
     $this->load->helper(array('form','url', 'security')); 
     $this->load->library(array('session', 'form_validation', 'email')); 
     $this->load->database(); 
     $this->load->model('User_model'); 
    } 

    function index() 
    { 
     $this->register(); 
    } 



    function register() 
    { 
     //set validation rules 
     $this->form_validation->set_rules('username', 'Username', 'trim|required|alpha|min_length[3]|max_length[30]|is_unique[instructors.instructors_slug]xss_clean'); 
     $this->form_validation->set_rules('mail', 'Email', 'trim|required|valid_email|is_unique[instructors.mail]'); 
     $this->form_validation->set_rules('password', 'password', 'trim|required|md5'); 
     $this->form_validation->set_rules('password2', 'Confirm Password', 'trim|required|md5|matches[password]'); 
     $to_email= $this->input->post('mail'); 

     $data['courses'] = $this->Popular_courses_model->get_popular_courses(); 
     $data['news'] = $this->News_model->get_news(); 


     //validate form input 
     if ($this->form_validation->run() == FALSE) 
     { 
      // fails 


      $this->load->view('templates/header'); 
      $this->load->view('pages/index', $data); 
      $this->load->view('templates/footer'); 
     } 
     else 
     { 
      //insert the user registration details into database 
      $data = array(
       'instructors_slug' => $this->input->post('username'), 
       'mail' => $to_email, 
       'password' => $this->input->post('password') 
      ); 

      // insert form data into database 
      if ($this->User_model->insertUser($data)) { 



       if ($this->User_model->sendEmail($to_email)) { 
        // successfully sent mail 
        $this->session->set_flashdata('msg','<div class="alert alert-success text-center">You are Successfully Registered! Please confirm the mail sent to your Email-ID!!!</div>'); 
        redirect('user/register'); 
       } 
       else 
       { 
        // error 
        $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">'.$to_email.' gondermir '.$this->email->print_debugger().'</div>'); 
        redirect('user/register'); 
       } 
      } 
      else 
      { 
       // error 
       $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">daxil elemir</div>'); 
        redirect('user/register'); 
      } 
     } 
    } 



    function verify($hash=NULL) 
    { 
     if ($this->User_model->verifyEmailID($hash)) 
     { 
      $this->session->set_flashdata('verify_msg','<div class="alert alert-success text-center">Your Email Address is successfully verified! Please login to access your account!</div>'); 
      redirect('user/register'); 
     } 
     else 
     { 
      $this->session->set_flashdata('verify_msg','<div class="alert alert-danger text-center">Sorry! There is error verifying your Email Address!</div>'); 
      redirect('user/register'); 
     } 
    } 
} 
?> 

そして、ここでは私のモデルである:

<?php 
class User_model extends CI_Model 
{ 
    function __construct() 
    { 
     // Call the Model constructor 
     parent::__construct(); 
    } 

    //insert into user table 
    function insertUser($data) 
    { 
     return $this->db->insert('instructors', $data); 
    } 


    //send verification email to user's email id 
    function sendEmail($to_email) 
    { 
     $from_email = '[email protected]'; //change this to yours 
     $subject = 'Verify Your Email Address'; 
     $message = 'Dear User,<br /><br />Please click on the below activation link to verify your email address.<br /><br /> http://www.wtf.az/user/verify/' . md5($to_email) . '<br /><br /><br />Thanks<br />Mydomain Team'; 

     //configure email settings 
     $config['protocol'] = 'smtp'; 
     $config['smtp_host'] = 'ssl://smtp.gmail.com'; //change this 
     $config['smtp_port'] = '465'; 
     $config['smtp_user'] = '[email protected]'; //change this 
     $config['smtp_pass'] = 'mypass'; //change this 
     $config['mailtype'] = 'html'; 
     $config['charset'] = 'utf-8'; 
     $config['wordwrap'] = TRUE; 
     $config['newline'] = "\r\n"; 
     $this->email->initialize($config); 

     //send mail 
     $this->load->library('email'); 
     $this->email->from($from_email, 'WTF'); 
     $this->email->to($to_email); 
     $this->email->subject($subject); 
     $this->email->message($message); 
     return $this->email->send(); 
    } 

    //activate user account 
    function verifyEmailID($key) 
    { 
     $data = array('status' => 1); 
     $this->db->where('md5(mail)', $key); 
     return $this->db->update('instructors', $data); 
    } 
} 
?> 
+0

私の勘を参照してみてください。 [PHP](http://php.net/manual/en/book.mail.php)のみで[mcve]を作成し、同じ結果が得られるかどうかを確認する必要があります。また、OSとWebサーバーで質問を更新する必要があります。 – mkaatman

答えて

0

$config['protocol'] = 'mail'; 

にごUser_model

$config['protocol'] = 'smtp'; 

にこのコードを変更したり、それがメールを送信するポートにバインドできなかったことである。このlink

関連する問題