Welcome Guest, Not a member yet? Register   Sign In
Send Email from Contact Form
#1

[eluser]elektra[/eluser]
Hi I'm fairly new to codeigniter and currently working on my final project.
I have build a contact form which should send an email to my email of the form details but it is not working at all.
server: XAMPP
ci ver: 2.1.0

Controller
Code:
public function send_email()
{
  $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
  $this->form_validation->set_rules('name', 'Full Name', 'required|alpha|xss_clean');
  $this->form_validation->set_rules('email', 'Email Address', 'required|valid_email|xss_clean');
  $this->form_validation->set_rules('telephone', 'Telephone', 'integer|xss_clean');
  $this->form_validation->set_rules('message', 'Message', 'required|min_length[10]||xss_clean');

  if($this->form_validation->run() == FALSE)
  {
   $data = array('title' => 'Contact Us', 'main_content'=> 'pages/contact');
   $this->load->view('template', $data);
  } else {
    
   $name = $this->input->post('name');
   $email = $this->input->post('email');
   $message = $this->input->post('message');
   $tel = $this->input->post('telephone');
   $enquiry = $this->input->post('enquiry');
  
   $config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
    'smtp_user' => '[email protected]',
    'smtp_pass' => 'password',
  'charset'  => 'iso-8859-1'
);
   $this->load->library('email', $config);
   $this->email->set_newline("\r\n");
   $this->email->from($email, $name);
   $this->email->to('[email protected]');
   $this->email->subject('Contact/Enquiry form');
   $this->email->message(array($message, $enquiry, $tel));

   if($this->email->send())
   {
    $data['success'] = array($this->session->set_flashdata('success', 'Your enquiry has successfully been submitted. Thank you.'), redirect(current_url()));

    $data = array('title' => 'Contact Us', 'main_content'=> 'pages/contact');
    $this->load->view('template', $data);
   }

Error

Quote:A PHP Error was encountered

Severity: Warning

Message: rtrim() expects parameter 1 to be string, array given

Filename: libraries/Email.php

Line Number: 383

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

Your email has failedUnable to send email using PHP mail(). Your server might not be configured to send mail using this method.
From: "asd"
Return-Path:
Reply-To: "[email protected]"
X-Sender: [email protected]
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <[email protected]>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
=?utf-8?Q?Contact/Enquiry_form?=

Running out of time and really need your kind help. Thank you very much.
#2

[eluser]Samus[/eluser]
you're running it on localhost. Make sure you set your smtp to that of your isp in php.ini

Have a read:

http://roshanbh.com.np/2007/12/sending-e...nment.html
#3

[eluser]CroNiX[/eluser]
Here's a pretty cool little fake mail server for windows.
#4

[eluser]Matalina[/eluser]
Your first error is your message is wrong. You need to make it a string not an array:

Code:
$this->email->message(array($message, $enquiry, $tel));

Needs to be something like;
Code:
$this->email->message($message.$enquiry.$tel);

I don't think it will affect smtp sending but it's likely it can.
#5

[eluser]elektra[/eluser]
[quote author="Matalina" date="1333657798"]Your first error is your message is wrong. You need to make it a string not an array:

Code:
$this->email->message(array($message, $enquiry, $tel));

Needs to be something like;
Code:
$this->email->message($message.$enquiry.$tel);

I don't think it will affect smtp sending but it's likely it can.[/quote]

Thank you yeah it doesn't affect smtp but it did solve one error. :-)
#6

[eluser]elektra[/eluser]
http://byitcurious.blogspot.co.uk/2009/0...mmand.html

Found this to be very useful but it still didn't send any email to my email.




Theme © iAndrew 2016 - Forum software by © MyBB