Welcome Guest, Not a member yet? Register   Sign In
Email sending problem
#1

[eluser]Cgull[/eluser]
Hello,

I have a contact form on my site, but it does not send the email.

I don't get any errors, it just goes back to the contact_view file, and does not send any email.

my Controller:

Code:
class Contact extends CI_Controller {
public function __construct()
{
     parent::__construct();
  }

  public function index()
  {
  $data['title'] = 'Contact Us';
  $data['view'] = 'contact';
   $data['mailSent'] = false;
  
    if ($this->input->post('send'))
    {
   $nospam = $this->input->post('nospam');
  
   if($nospam == '')
   {
    $this -> load -> library( 'form_validation' );
    $this -> form_validation -> set_error_delimiters('<div class="error">', '</div>');
    $this -> form_validation -> set_rules( 'name', 'Name', 'required|min_length[2]' );
    $this -> form_validation -> set_rules( 'email', 'Email', 'required|valid_email' );
    $this -> form_validation -> set_rules( 'message', 'Message', 'required' );
  
    if ( $this -> form_validation -> run() === TRUE )
    {
     # Loading email library of Codeigniter
        $this->load->library('email');
        # Loading configuration file mail_config.php
        $this->config->load('email_config',true);
        # Setting email address and name of the person sending the email
        $this->email->from($this->input->post('email'),$this->input->post('name'));
        # Setting email address of the recipient
     $this->email->to($this->config->item('to','email_config'));
        # Setting email subject
        $this->email->subject('Contact form submition - Highland Coffee Roastery');
     # Setting email message body
        $this->email->message($this->input->post('message',true));
        # If mail sending successful
        if ($this->email->send())
        {
         # If $mail_sent = true; it will show a success message.
          $data['mailSent'] = true;
        }
      }
       # Showing Contact Form
    $this->load->view('index_view', $data);
   }
  }
  else
  {
   # Showing Contact Form
    $this->load->view('index_view', $data);
  }
  $this->load->view('index_view',$data);
}
}

My email config file:
Code:
$config['to'] = '[email protected]';
$config['protocol'] = 'mail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;

Am I doing something wrong?

Thanks
#2

[eluser]InsiteFX[/eluser]
Code:
echo $this->email->print_debugger();
#3

[eluser]Cgull[/eluser]
Thanks but where do I put this?

I put it in the controller, but nothing is displaying.
#4

[eluser]InsiteFX[/eluser]
Right afteryou send the email
#5

[eluser]Cgull[/eluser]
Ok, managed to view the debugger error, tried with mail and with sendmail and both give me error: Your server might not be configured to send mail using this method.

Wrote to my host.

Thank you
#6

[eluser]Cgull[/eluser]
Ok, the host said there was no recipient address.

I changed this line:
Code:
$this->email->to($this->config->item('to','email_config'));

to:
Code:
$this->email->to('myemailaddress')

And now it works.

Any idea why it didn't work the other way?

#7

[eluser]InsiteFX[/eluser]
Because this is wrong!
Code:
$this->email->to($this->config->item('to','email_config'));

Try this:
Code:
$config['email_to'] = '[email protected]';

$this->email->to($this->config->item('email_to'));




Theme © iAndrew 2016 - Forum software by © MyBB