2016-10-26 3 views
0

使用codeigniterPHP working.Dataが正常に挿入されていないを使用してデータベースにデータを挿入した後に電子メールを送信するデータの挿入後に電子メールを送信するが、MAIL機能がwww.hostname.comページには、いずれかをworking.Canされていないとなって機能していませんこれを手伝ってください。事前に感謝します。私のコードはここにあります。のCodeIgniter PHP

コントローラー:

class Blog extends CI_Controller 
{ 
    function __construct() 
     { 
      parent::__construct(); 
      //here we will autoload the pagination library    
      $this->load->model('blogs_model'); 
      $this->load->library('email'); 
     } 
     function addcomments() 
    { 
     $this->load->library('form_validation'); 
     $this->form_validation->set_error_delimiters('<br /><span class="error"> ','</span>'); 
     $this->form_validation->set_rules('first_name','First Name' , 'required'); 
     $this->form_validation->set_rules('email','Email'); 
     $this->form_validation->set_rules('location','Location'); 
     $this->form_validation->set_rules('description','Description'); 
     if($this->form_validation->run()== FALSE) 
     { 
     $data['mainpage']='blogs'; 
     $this->load->view('templates/template',$data); 
     } 
     else 
     { 

      //insert the user registration details into database 
      $data=array(
       'blog_id'=>$this->input->post('bl_id'), 
       'first_name'=>$this->input->post('first_name'), 
       'email'=>$this->input->post('email'), 
       'description'=>$this->input->post('description'), 
       'location'=>$this->input->post('location') 
       ); 
      // insert form data into database 
      if ($this->blogs_model -> insertcomments($data)) 
      { 
       // send email 
       if ($this->blogs_model->send_mail($this->input->post('email'))) 
       { 
        // successfully sent mail 
        $this->flash->success('msg','<div class="alert alert-success text-center">You are Successfully Registered! Please confirm the mail sent to your Email-ID!!!</div>'); 
        redirect("blog"); 
       } 
       else 
       { 
        // error 
        $this->flash->success('msg','<div class="alert alert-danger text-center">Oops! Error. Please try again later!!!</div>'); 
        redirect("blog"); 
       } 
      } 
      else 
      { 
       // error 
       $this->flash->success('msg','<div class="alert alert-danger text-center">Oops! Error. Please try again later!!!</div>'); 
       redirect('blog'); 
      } 
     } 
     } 
} 

モデル:

$this->blogs_model->send_mail($this->input->post('email')) 

正しい関数名は次のとおりです。

function insertcomments($data) 
{ 
    return $this->db->insert('comments', $data); 
    //$this->db->insert('comments',$data); 
    //return $this->input->post('bl_id'); 
} 

function sendEmail($to_email) 
{ 

    //configure email settings 
    $config=Array(
    'protocol'=> 'smtp', 
    'smtp_host' => 'ssl://smtp.googlemail.com', //smtp host name 
    'smtp_port' => '465', //smtp port number 
    'smtp_user' => '[email protected]', 
    'smtp_pass' => '************', //$from_email password 
    'mailtype' =>'html', 
    'charset' => 'iso-8859-1', 
    'wordwrap' => TRUE 
    ); 

    //send mail 
    $this->load->library('email',$config); 
    $this->email->from('[email protected]', 'Admin'); 
    $this->email->to('[email protected]'); 
    $this->email->subject('Comments'); 
    $this->email->message('Testing'); 
    $this->email->set_newline("\r\n"); 
    return $this->email->send(); 
} 
+0

これを試してみてください: '場合(の$ this - > email-> send()) { echo "sent"; } else { echo $ this-> email-> print_debugger(); } 'がエラーを見つけるのに役立ちます – devpro

+0

@devproと同じエラーが発生するwww.developer.domain.comページが機能しません www.developer.domain.comは現在このリクエストを処理できません。 HTTPエラー500 – user7047368

+0

これはメソッド名の問題であり、間違ったものを使用していると思います。 – devpro

答えて

0

あなたのコントローラに電子メールを送信するために間違ったメソッド名を使用していますsendEmail()

$this->blogs_model->sendEmail($this->input->post('email')) 
+1

ありがとうございました – user7047368

+0

@ user7047368:うれしいことに助けてください – devpro

0

あなたのコードをチェックしてください:モデルにあなたは "のsendEmail" を使用しているため

あなたのコントローラで " send_mail を" 機能を変更する必要があります。お使いのコントローラにで

変更:

$this->blogs_model->sendEmail($this->input->post('email')) 
0

私はあなたのコードの問題は、このライン smtp_host' => 'ssl://smtp.googlemail.com

が代わりにしてみてくださいだと思う:smtp_host' => 'http://smtp.gmail.com