[eluser]Keloo[/eluser]
I'm trying to send emails with the CI email lib, and I'm getting some errors like:
Quote: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: 1540
An Error Was Encountered
Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.
From: "Some name"
Return-Path:
Reply-To: "someone@yahoo.com"
X-Sender: someone@yahoo.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <4dbe8ae281f65@yahoo.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
=?utf-8?Q?Testing_mail?=
This is just a test
here is the function responsible for sending emails:
Code:
function contact()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('contact-email', 'Email', 'trim|required|valid_email');
$this->form_validation->set_rules('contact-name', 'Name', 'trim|required|min_length[5]');
$this->form_validation->set_rules('subject', 'Subject', 'trim|required|min_length[5]');
$this->form_validation->set_rules('message', 'Message', 'trim|required|max_length[500]');
if($this->form_validation->run() == FALSE)
{
$data['body'] = "Contact";
$data['title'] = 'Site/Contact';
$data['main_content'] = 'contact';
$this->load->view('includes/template',$data);
}
else
{
$config = Array(
'protocol' => 'sendmail',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '[email protected]',
'smtp_pass' => 'testing'
);
$this->load->library('email');
$this->email->from($this->input->post('contact-email'), $this->input->post('contact-name'));
$this->email->to('[email protected]');
$this->email->subject($this->input->post('subject'));
$this->email->message($this->input->post('message'));
$this->load->library('email',$config);
$this->email->set_newline("\r\n");
if($this->email->send())
{
$data['body'] = "Contact";
$data['title'] = 'Site/Contact';
$data['main_content'] = 'contact_success';
$this->load->view('includes/template',$data);
}
else
{
show_error($this->email->print_debugger());
}
}
}
and the view:
Code:
<aside class="grid_13 omega push_2 prefix_1">
<?php $logged_in = $this->session->userdata('logged_in'); ?>
<?php if(!isset($logged_in) || $logged_in != TRUE): ?>
<?php $this->load->view('includes/login_form'); ?>
<?php else: ?>
<?php $this->load->view('includes/users_area'); ?>
<?php endif?>
</aside>
</header>
<div id="page-wrap" class="container_24">
<section id="main" class="grid_16 push_4">
<h2>Contact</h2>
<?php echo form_open('site/contact'); ?>
<fieldset>
<label>From: </label>
<input type="email" name="contact-email" value="<?php echo set_value('contact-email'); ?>" />
<?php echo form_error('contact-email','<p class="error">','</p>'); ?>
<label>Name: </label>
<input type="text" name="contact-name" value="<?php echo set_value('contact-name'); ?>" />
<?php echo form_error('contact-name','<p class="error">','</p>'); ?>
<label for="subject">Subject: </label>
<input type="text" name="subject" id="subject" value="<?php echo set_value('subject'); ?>"/>
<?php echo form_error('subject','<p class="error">','</p>'); ?>
<label for="message">Message: </label>
<p><textarea name="message" rows="10" cols="50" value="<?php echo set_value('message'); ?>"></textarea></p>
<?php echo form_error('message','<p class="error">','</p>'); ?>
<button type="submit">Send </button>
</fieldset>
</form>
</section>
</div>
I really can't figure out what I'm doing wrong... How should I make it work ?