[eluser]Tom Glover[/eluser]
This works, just need to set your SMTP settings if on windows or leave it as it is, if it doesn't work on *nix try "send mail" or "php mail" or "SMTP" as the protocol. SMTP will work which ever server.
Controller for email sending:
Code:
function index()
{
$form['state'] = "1";
$data['content'] = $this->load->view('contact',$form,true);
$data['pageTitle'] = 'Contact us';
$data['introText'] = "Below are way in how to contact us at ******.com";
$this->load->view('template',$data);
}
function send(){
$this->load->helper(array('form'));
$rules['name'] = "required|encode_php_tags|xxs_clean";
$rules['email'] = "required|valid_email";
$rules['tel'] = "required|numeric";
$rules['subject'] = "required|encode_php_tags|xxs_clean";
$rules['message'] = "required|encode_php_tags|xxs_clean";
$this->validation->set_rules($rules);
if ($this->validation->run() == FALSE)
{
$form['state'] = "1";
$data['content'] = $this->load->view('contact',$form,true);
$data['pageTitle'] = 'Contact us';
$data['introText'] = "Below are way in how to contact us at ******.com";
$this->load->view('template',$data);
}
else
{
$form['state'] = "2";
$data['content'] = $this->load->view('contact',$form,true);
$data['pageTitle'] = 'Contact us';
$data['introText'] = "Below are way in how to contact us at ******.com";
$this->load->view('template',$data);
//Write and Send Email//
$this->load->library('email');
/*$config['smtp_host'] = '**********************';
$config['smtp_user'] = '******************';
$config['smtp_pass'] = '******';*/
$config['protocol'] = 'sendmail';
$config['useragent'] = 'WebSite - ************';
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->from('***************', '***********');
$this->email->reply_to($_POST['email'], $_POST['name']);
$this->email->to('*******************');
if ($_POST['copyEmail'] == 1){
$this->email->cc($_POST['email']);
$message['clientCopy'] = 'Email copied to client.';
}
$this->email->subject($_POST['subject'].' - Web-Site Form');
//construct the messsage//
$message['name'] = $_POST['name'];
$message['tel'] = $_POST['tel'];
$message['email'] = $_POST['email'];
$message['subject'] = $_POST['subject'];
$message['message'] = $_POST['message'];
$message['clientCopy'] = 'Email copied to client.';
//output message as var//
$this->email->message($this->load->view('email',$message,true)); // creates and loads view, instead of outputting it sends code.
// Send email
$this->email->send();
//Uncoment Below for Debugger//
//echo $this->email->print_debugger();
}
View file of the email html:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html ><style type="text/css">
<!--
body,td,th {
color: #FFFFFF;
}
body {
background-color: #996633;
}
h1{
font-size: 16px;
font-weight: bold;
color: #FFFFFF;
border-bottom: medium solid #FFFFFF;
}
-->
</style>
<body>
<div id="content">
<h1>Web Form Inquiry</h1>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20%" valign="middle"><div align="right"><strong>Full Name: </strong></div></td>
<td width="335" valign="middle"><?php echo $name?></td>
</tr>
<tr>
<td valign="middle"><div align="right"><strong>Email:</strong></div></td>
<td valign="middle"><?php echo $email?></td>
</tr>
<tr>
<td valign="middle"><div align="right"><strong>Telephone:</strong></div></td>
<td valign="middle"><?php echo $tel?></td>
</tr>
<tr>
<td valign="middle"><div align="right"><strong>Subject:</strong></div></td>
<td valign="middle"><?php echo $subject?></td>
</tr>
<tr>
<td height="60" valign="middle"><div align="right"><strong>Message:</strong></div></td>
<td width="80%" valign="middle"><?php echo $message?></td>
</tr>
<tr>
<td colspan="2" valign="middle"><?php echo $clientCopy ?></td>
</tr>
</table>
<p> </p></div>
</body>
</html>