CodeIgniter Forums

Full Version: Email sending takes 36 seconds!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]dobbler[/eluser]
Hi,

I'm writing a password reset function where the new password gets sent via email. Here is the code:

Code:
$this->load->library('email');                        
                        
$this->email->from('no-reply@website.com', 'Website Administration');
$this->email->to($email);

$this->email->bcc('mail@address.com');
$this->email->subject('Password Reset');
$msg = "Dear " . $check_user['FirstName'] . ",\n\n";
$msg .= "Your password has been reset to: " . $new_pass . "\n\n";
$msg .= "Please login using this new password at: http://www.website.com where you will be asked to change this temporary password to something more personal.\n\nThank you,\n\nWebsite.com\n";

$this->email->message($msg);

$this->email->send();

I've tried no config, which I presume defaults to the mail protocol and config with sendmail but both are really really slow 28 seconds & 36 seconds respectively. I'm currently testing on a temporary server so I don't have access to smtp properly yet.

Is there something I'm missing?

Thanks.

El Forum

[eluser]xwero[/eluser]
are you talking about the mail going from php to the mailserver or from the mailserver to actually sending the mail?

E-mail is not an instant communication service. So you are not getting your email as soon as you send it.

El Forum

[eluser]dobbler[/eluser]
Thanks xwero, but I'm not that impatient!

No, the page is freezing upon submission of the form for up to 40 seconds. Then it goes to the success page and the mail gets sent so the whole thing is working but that freeze is not cool because nothing is happening for the user..

Any thoughts?

El Forum

[eluser]xwero[/eluser]
Add benchmarks markers where you think the problem is. For example
Code:
$this->benchmark->mark('to_class');
$this->email->message($msg);
$this->benchmark->mark('to_server');
$this->email->send();
$this->benchmark->mark('done');
echo $this->benchmark->elapsed_time('to_class', 'to_server');
echo $this->benchmark->elapsed_time('to_server', 'done');
If the elapsed times are short the problem lays somewhere else.

El Forum

[eluser]dobbler[/eluser]
Hi zwero,

Thanks for your reply. Here's what I got from the benchmark test:

('to_class', 'to_server') = 0.0000

('to_server', 'done') = 32.7540

So it seems clear that it's the $this->email->send(); that's taking the time. God knows why it's taking that long..

Thanks for your help so far, any ideas? Anyone??

El Forum

[eluser]xwero[/eluser]
Have you tried using a public mail server to send a test mail? I think the problem has to be with your server. I saw a few other posts where it was mentioned the email class was slow but half a minute page freeze is long. Maybe you should use an of the shelf library like swift mailer for emailing.

El Forum

[eluser]dobbler[/eluser]
I had planned on using phpMailer to handle the more intensive emailing but for cheap & nasty single emailing I was hoping the email class would handle it. Either way, I think you're right that it's something to do with the server.

Thanks again for your time & help. Btw, would u recommend swiftmailer over Phpmailer and for any particular reason? I guess it comes down to personal preference in the end..

El Forum

[eluser]xwero[/eluser]
It was the first library that popped up in my head Smile