Welcome Guest, Not a member yet? Register   Sign In
Help with email - I'm new to CI
#1

[eluser]ChaosKnight[/eluser]
Hi, I started using CI yesterday and I'm loving it! There's only a few things that still bothers me... Firstly I find my own code very... very... very... slow... I don't know if it's only because I haven't enabled the cache yet. If someone can find the time to quickly look through my controller code, I'd really appreciate any help.

Contact controller
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

  class Contact extends Controller
  {
    function index()
    {
      $this->load->helper(array('html','url','form'));
      $this->load->library('form_validation');
      $this->load->library('email');

      $this->form_validation->set_error_delimiters('<div class="error">','</div>');

      $rules['name']="trim|required|xss_clean";
      $rules['email']="trim|required|valid_email|xss_clean";
      $rules['subject']="trim|required|xss_clean";
      $rules['message']="trim|required|xss_clean";

      $this->form_validation->set_rules($rules);

      $data['page_title'] = 'Contact Us';

      if ($this->form_validation->run() == FALSE)
      {
    $this->load->view('header',$data);
    $this->load->view('nav');
    $this->load->view('sidebar');
    $this->load->view('contact');
    $this->load->view('footer');
      }
      else
      {
    $this->email->from('[email address]','[name]');
    $this->email->to('[email address]');

    $this->email->subject($_POST['subject']);
    $this->email->message($_POST['message']);

    $data['title']='Contact Us';
    $data['flash']=$this->email->send()?'The message has been recieved, thank
                       you!':'The message could not be sent, please try again.';

    $this->load->view('header',$data);
    $this->load->view('nav');
    $this->load->view('sidebar');
    $this->load->view('contact');
    $this->load->view('footer');

      }
    }
  }
/* End of Contact.php controller */

At the moment that code does nothing, I can't see why... The contact view is very basic, it's only a page with 4 fields (name, email, subject and message)

If someone can tell me why it's so slow and what I did wrong, I would be really grateful, thanks!

Oh and the email config page is where the tutorial told me to put it config/email.php

Thanks!
#2

[eluser]mddd[/eluser]
Code:
$this->email->from('[email address]','[name]');
$this->email->to('[email address]');
These lines don't do anything. You need to put real information in there. Like so:
Code:
$this->email->from(set_value('email'), set_value('name'));
$this->email->to('youradministratoraddress@example'); // replace this with your real address!

Also, if you use information from POST and you use the validation library, DON'T call the POST variables directly!
Otherwise what's the point.. So in stead of this:
Code:
$this->email->subject($_POST['subject']);
$this->email->message($_POST['message']);
do this:
Code:
$this->email->subject(set_value('subject'));
$this->email->message(set_value('message'));
#3

[eluser]ChaosKnight[/eluser]
Thanks for your reply, I have used my real mail address there, I only took it out when I posted my code here, I once posted my real address on a forum and I got spammed like hell... I'll implement your other suggestion, thanks for that... But do you perhaps know why it's so slow?

Thanks!

[Edit]:
The email still doesn't get sent, it only loads extremely long, about 30 to 60 seconds, then the page just returns empty, not even the views are sent back to the browser
#4

[eluser]daelsepara[/eluser]
is sendmail, postmaster, (or equivalent) configured properly?

on a linux machine, you can test whether or not a simple message gets sent.
#5

[eluser]mddd[/eluser]
I agree with that last post. If email sending isn't configured correctly, the server could be trying to find a server that doesn't exist.. it will stop trying after a certain timeout (30 seconds?).. that will make it very slow indeed.
#6

[eluser]ChaosKnight[/eluser]
I am upgrading an existing PHP website to CodeIgniter, the host unfortunately only has Windows servers running IIS, but on the previous pages I have managed to send the email from the Contact page quite fast. The mail server only requires normal SMTP authentication, and only allow the outgoing SMTP protocol.

Here is the email.php file located at application/config:
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  $config['protocol']='smtp';
  $config['smtp_host']='[host]';
  $config['smtp_user']='[user]';
  $config['smtp_pass']='[pass]';
/* End of Email.php config file */
Once again I have left out the real details, as this is very confidential.

Is there additional settings that I have left out?
The host uses the default port.
#7

[eluser]daelsepara[/eluser]
have you tried a telnet command to the host and port to see if it responds?

if it does it could be that the smtp host does not know where to route your emails.
#8

[eluser]ChaosKnight[/eluser]
The host offers a control panel, I checked in the control panel, and forwards all the mail correctly... I'll check everything again, thanks
#9

[eluser]RonMcClung[/eluser]
I am having similar difficulty with the same kind of situation... SMTP Auth, on a Windows/IIS box. I get the 30 sec timeout... set the smtp_timeout to 300... default port....

What am I doing wrong?




Theme © iAndrew 2016 - Forum software by © MyBB