dimanche 19 avril 2015

Codeigniter contact form email

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 it up so that it emails the results I get an error. I've looked around and tried a few different solutions but I can't figure out what it is that I'm doing wrong.


Controller:



public function contact()
{
$this->load->helper('form');
$this->load->library('form_validation');

$this->form_validation->set_rules('name', 'your name', 'required', array('required'=>"<p class='required'>Please provide %s</p><br>"));
$this->form_validation->set_rules('email', 'your email address', 'required', array('required'=>"<p class='required'>Please provide %s</p><br>"));


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' => 'smtp.mydomain.co.uk',
'smtp_port' => 465,
'smtp_user' => 'example@mydomain.co.uk',
'smtp_pass' => 'mypassword',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE,
);

$message = 'This is a test message... do I work?';

$this->load->library('email');
$this->email->initialize($config);
$this->email->from('ecample@example.co.uk', 'Tester');
$this->email->to('example@mydomain.co.uk');
$this->email->subject('New Query');
$this->email->message($message);
$this->email->send();

if($this->email->send()){
$this->load->view('templates/headder');
$this->load->view('sent');
$this->load->view('templates/footer');
}
else
{
$this->load->view('templates/headder');
$this->load->view('contact');
$this->load->view('templates/footer');
}
}
}


View:



<?php echo form_open('home/contact'); ?>
<h3><span class='required'>*</span>Name:</h3>
<label><input type='text' name='name' value="<?php echo set_value('name'); ?>" maxlength="50" ></label>
<?php echo form_error('name'); ?>
<h3>Company:</h3>
<label><input type='text' name='company' value="<?php echo set_value('company'); ?>" maxlength="100"></label>
<h3><span class='required'>*</span>eMail:</h3>
<label><input type='email' name='email' value="<?php echo set_value('email'); ?>" maxlength="100"></label>
<?php echo form_error('email'); ?>
<input id='submit_button' type='submit' value='Submit'>


Error Message:



A PHP Error was encountered

Severity: Notice

Message: fwrite(): send of 11 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host.

Filename: libraries/Email.php

Line Number: 2131

Backtrace:

File: C:\xampp\htdocs\root\CI\application\controllers\home.php
Line: 80
Function: send

File: C:\xampp\htdocs\root\public_html\index.php
Line: 292
Function: require_once


Any advice would be much appreciated.


Aucun commentaire:

Enregistrer un commentaire