Codeigniter contact form email

后端 未结 2 816
名媛妹妹
名媛妹妹 2021-01-28 17:15

I\'m trying to set up a contact form in Codeigniter (I\'m running on xampp using Apache and I have a virtual host set up). I have the actual form working but when I try to link

2条回答
  •  再見小時候
    2021-01-28 17:34

    I think perhaps email smpt needs ssl:// and if you are using xampp or wamp for testing email you need to configure the mail settings.

    'smtp_host' => 'smtp.mydomain.co.uk',
    

    And Should Be

    'smtp_host' => 'ssl://smtp.mydomain.co.uk';
    

    How to setup email on xampp

    https://www.youtube.com/watch?v=TO7MfDcM-Ho

    public function contact() {
    $this->load->helper('form');
    $this->load->library('form_validation');
    $this->load->library('email');
    $this->load->library('url');
    
    $this->form_validation->set_rules('name', 'Your Name', 'required');
    $this->form_validation->set_rules('email', 'your email address', 'required');
    
    // Removed Array From Form Validation
    
    
    if($this->form_validation->run() == FALSE) {
    
    $this->load->view('templates/headder');
    $this->load->view('contact');
    $this->load->view('templates/footer');
    
    } else {
    
    $config = array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.mydomain.co.uk',
    'smtp_port' => 465,
    'smtp_user' => 'example@mydomain.co.uk',
    'smtp_pass' => 'mypassword',
    'charset' => 'iso-8859-1',
    'wordwrap' => TRUE,
    );
    
    $this->email->initialize($config);
    $this->email->from('ecample@example.co.uk', 'Tester');
    $this->email->to('example@mydomain.co.uk');
    $this->email->subject('New Query');
    $message = 'This is a test message... do I work?';
    $this->email->message($message);
    
    if($this->email->send()){
    $this->load->view('templates/header'); // Fix spelling Mistake hedder
    $this->load->view('sent');
    $this->load->view('templates/footer');
    } else {
    $this->load->view('templates/header'); // Fix spelling Mistake hedder
    $this->load->view('contact');
    $this->load->view('templates/footer');
    }
    }
    }
    

提交回复
热议问题