Welcome Guest, Not a member yet? Register   Sign In
email bug
#1

[eluser]pocketmax[/eluser]
every time I try to send an email using the email lib module, the page just hangs. Heres my code...

Code:
$this->load->library('email');
                $this->email->initialize(array(
                        'protocol'=>'smtp',
                        'smtp_port'=>25,
                        'smtp_host'=>'192.168.1.4',
                        'mailtype'=>'plain'
                ));
                $this->email->from('[email protected]');
                $this->email->reply_to('[email protected]');
                $this->email->to('[email protected]');
                $this->email->subject('my subject');
                $this->email->message('test body');
                $this->email->send();

I searched and there are about 3 or 4 previous posts about this issue but I'm totally convinced this is a bug and this is why...

1. I'm able to manually connect to port 25 on that ip using fsockopen in a separate script.
2. I telneted into port 25 on that server and did all the SMTP commands to make an email and send it to myself and it worked perfectly fine.

But when I load the email lib and do such a simple routine in ci, it just hangs. When I try a different ip address that I know doesn't have smtp turned on, it returns a connection timeout error. So that tells me that it does connect but something gets screwed up along the way.
#2

[eluser]pocketmax[/eluser]
sorry, posted this twice in http://ellislab.com/forums/viewthread/143724/

How do you delete posts if your the author of it?
#3

[eluser]cereal[/eluser]
You have to specify user and password to connect to the smtp server, try this way:

Code:
$this->load->library('email');
        $config['protocol'] = 'smtp';
        $config['smtp_host'] = 'smtp.yourhost.here';
        $config['smtp_user'] = 'your_user';
        $config['smtp_pass'] = 'your_password';
        $config['useragent'] = 'your user_agent';
        $config['charset'] = 'utf8';
        $config['wordwrap'] = TRUE;
        $this->email->initialize($config);
        //your code here
#4

[eluser]pocketmax[/eluser]
But I didn't have to do that before. Besides, it's smtp and all the emails are going to the same @domain.com. I'm not doing any open relay stuff. I'm just sending emails to accounts that are on the email server.
#5

[eluser]pocketmax[/eluser]
Whats weird is I can telnet into port 25 of the mail server and using SMTP commands, I can send an email to a local account just fine but when I use CI, it just hangs.
#6

[eluser]pocketmax[/eluser]
OK, this is an officially ridiculous bug in CI, why because my code ran fine in cakePHP...

Code:
$this->Email->to = '[email protected]';
                $this->Email->subject = 'test subject';
                $this->Email->replyTo = '[email protected]';
                $this->Email->from = '[email protected]';
                $this->Email->delivery = 'smtp';
                $this->Email->sendAs = 'html';
                $this->Email->smtpOptions=array(
                        'port'=>25,
                        'host'=>'192.168.1.4'
                );
                $this->Email->send('test');

OMG, this is so ridiculous. There was nothing wrong with my email server, it was ci the whole time! And after looking at some of the other posts about this, most of them either gave up or used third party plug-ins because they lost faith in ci's way of sending emails. This is so pathetic!
#7

[eluser]g_montel[/eluser]
I'm experiencing the same problem.
I'm running CI 1.7.2 on a xampp server version 1.7.3 on windows xp.

I'm sending an email with the following code :

Code:
log_message('debug', '[Contact_model.save_contact_form_and_send_email_to_admins] before sending email');

        // send email to admins
        $this->load->library('email');
        log_message('debug', '[Contact_model.save_contact_form_and_send_email_to_admins] debugger = '.$this->email->print_debugger());
        $this->email->to($this->config->item('myapp_administrator_emails'));
        $this->email->from($this->config->item('myapp_do_not_reply_email'),$this->config->item('myapp_do_not_reply_name'));
        $this->email->subject($this->config->item('myapp_name').' | new form received on the website');
        $body = 'Date : '.mdate($datestring)."\r\n"
        .'Sender IP address : '.$ip_address."\r\n"
        .'Sender user agent : '.$user_agent."\r\n"
        .'Sender name : '.$name."\r\n"
        .'Sender email : '.$email."\r\n"
        .'Subject : '.$subject."\r\n"
        .'Message : '.$message."\r\n";

        $this->email->message($body);
        
        log_message('error', '[Contact_model.save_contact_form_and_send_email_to_admins] before email->send');
        
        if (!$this->email->send())
        {
            log_message('error', '[Contact_model.save_contact_form_and_send_email_to_admins] unable to send email to '.$this->config->item('myapp_administrator_emails'));
        }
        else {
            log_message('error', '[Contact_model.save_contact_form_and_send_email_to_admins] email sent to '.$this->config->item('myapp_administrator_emails'));        
        }
        
        log_message('error', '[Contact_model.save_contact_form_and_send_email_to_admins] after email->send');

The mail IS sent and arrives on my mailbox.

But the $this->email->send() function just never returns.

Here are the logs :
Code:
DEBUG - 2010-11-22 11:24:03 --> [Contact_model.save_contact_form_and_send_email_to_admins] before sending email
DEBUG - 2010-11-22 11:24:03 --> Email Class Initialized
DEBUG - 2010-11-22 11:24:03 --&gt; [Contact_model.save_contact_form_and_send_email_to_admins] debugger = <pre>

</pre>
ERROR - 2010-11-22 11:24:03 --&gt; [Contact_model.save_contact_form_and_send_email_to_admins] before email->send

The following PHP code
Code:
echo "trysendmail.php\n";
$from_name = "xxx";
$from_email = "[email protected]";
$headers = "From: $from_name <$from_email>";
$body = "Hi, \nThis is a test mail from $from_name <$from_email>.";
$subject = "Test mail from Justrealized";
$to = "[email protected]";

if (mail($to, $subject, $body, $headers)) {
  echo "success!";
} else {
  echo "fail…";
}

works, is sending the mail, and prints "success!".

Any hint ?
Many thanks in advance

Geoffroy
#8

[eluser]cereal[/eluser]
Set NULL in email->to() and check if the error is logged. I think the problem could be related to your using of $this->config->item() if you are running PHP 4.* then config is a reserved word:

http://ellislab.com/codeigniter/user-gui...names.html

bye!
#9

[eluser]g_montel[/eluser]
I found my error.
It was hunging at the following line in EMAIL.PHP
Code:
$this->_set_error_message('email_sent', $this->_get_protocol());

The problem is I didn't have email_lang.php in my application language folder...

Hope it will help other people!

Best

geoffroy
#10

[eluser]Chris abcdefg[/eluser]
dont use CI email lib its bollox and sends the wrong headers for Standard SMTP
http://ellislab.com/forums/viewthread/183282/




Theme © iAndrew 2016 - Forum software by © MyBB