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
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');
}
}
}
As it turns out a number of factors seem to have contributed to this problem. First, I needed to configure some PHP settings, second certain email addresses were blocking the connection (gmail and live mail) so I switched to using an email address on a domain I own which was fine, and finally, just to make things interesting my email account was having technical problems which have now been resolved resulting in about 20 test messages being sent through this morning.
What I did;
In Xampp/PHP/php.ini:
uncomment sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t", the comment out the next instance of sendmail_path.
uncomment extension=php_openssl.dll
Go into Xampp/sendmail/sendmail.ini:
Go to smtp_server and set to your smtp extension (smtp.yourdomain.com) a few lines under this will be a section for username and password. Set this to the username and password for your email account.
I also used the following program within a controller to check that all relevant ports were open:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Test extends CI_Controller {
public function index()
{
$fp = fsockopen("www.google.com", 80, $errno, $errstr, 10);
if (!$fp)
echo "www.google.com - $errstr ($errno)<br>\n";
else
echo "www.google.com - ok<br>\n";
$fp = fsockopen("smtp.yourdomain.com", 465, $errno, $errstr, 10);
if (!$fp)
echo "smtp.yourdomain.com 465 - $errstr ($errno)<br>\n";
else
echo "smtp.yourdomain.com 465 - ok<br>\n";
$fp = fsockopen("smtp.yourdomain.com", 587, $errno, $errstr, 10);
if (!$fp)
echo "smtp.yourdomain.com - $errstr ($errno)<br>\n";
else
echo "smtp.yourdomain.com - ok<br>\n";
$fp = fsockopen("smtp.yourdomain.com", 25, $errno, $errstr, 10);
if (!$fp)
echo "smtp.yourdomain.com - $errstr ($errno)<br>\n";
else
echo "smtp.yourdomain.com 25 - ok<br>\n";
}
}