[eluser]Masum[/eluser]
MY FORM PAGE: myform.php
Code:
<html>
<head>
<title>My Form</title>
<style type="text/css">
p { color:#F00;}
</style>
</head>
<body>
<?php echo form_open('form'); ?>
<table width="900px" align="center">
<tr>
<td align="right">Full Name</td>
<td width="100px"><input type="text" name="full_name" value="<?php echo set_value('full_name'); ?>" size="50" /></td>
<td align="left"><p><?php echo form_error('full_name'); ?></p></td>
</tr>
<tr>
<td align="right">Email Address</td>
<td><input type="text" name="email" value="<?php echo set_value('email'); ?>" size="50" /></td>
<td align="left"><p><?php echo form_error('email'); ?></p></td>
</tr>
<tr>
<td align="right">Subject:</td>
<td><input type="text" name="subject" value="<?php echo set_value('subject'); ?>" size="20" /></td>
<td align="left"><p><?php echo form_error('subject'); ?></p></td>
</tr>
<tr>
<td align="right">Comment</td>
<td><textarea name="comment" rows="5" cols="40"><?php echo set_value('comment'); ?></textarea></td>
<td align="left"><p><?php echo form_error('comment'); ?></p></td>
</tr>
<tr>
<td></td>
<td align="left"><input type="submit" value="Submit" /></td>
<td></td>
</tr>
</table>
</form>
</body>
</html>
MY CONTROLLER: form.php
Code:
<?php
class Form extends CI_Controller
{
function index()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('full_name', 'Full Name', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
$this->form_validation->set_rules('subject', 'Subject', 'required');
$this->form_validation->set_rules('comment', 'Comment', 'required');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('myform');
}
else
{
$this->load->library('email');
$this->config->item('protocol');
$this->email->from($this->input->post('email'), $this->input->post('full_name'));
$this->email->to('[email protected]');
$this->email->subject('Email Test');
$this->email->message($this->input->post('comment'));
if($this->email->send())
{
echo 'Your email has been sent';
}
else
{
show_error($this->email->print_debugger());
}
}
}
}
?>
CONFIG FILE: email.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'localhost';
$config['smtp_port'] = 25;
$config['mailtype'] = 'html';
GETTING ERROR:
A PHP Error was encountered
Severity: Warning
Message: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
Filename: libraries/Email.php
Line Number: 1553
An Error Was Encountered
Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.
From: "Masum"
Return-Path:
Reply-To: "jamalganj@
yahoo.com"
X-Sender: jamalganj@
yahoo.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <4f1d1b61e67d7@
yahoo.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
=?utf-8?Q?Email_Test?=
tyh