Welcome Guest, Not a member yet? Register   Sign In
Sending email from gmail now causing fatal timeout error... it used to work :-s
#1

[eluser]boltsabre[/eluser]
Hi everyone, not sure what I've done here, hoping it's just a brain fade and someone can pick the error up in 2 seconds flat!

Okay, I cannot send (anymore, used to work...) emails from my application via gmail anymore.

- Log files don't show anything helpful, no errors, just the DEBUG logs.
- Through my own testing using echo statements, I've determined that $CI->email->send() never finishes, in fact after 300 seconds I get a fatal timeout on my screen.
Quote:Fatal error: Maximum execution time of 300 seconds exceeded in C:\MySites\www.localdownundr.com\system\libraries\Email.php on line 1869

Here is my config/email file, I have some stuff set up in there for local vs testing/staging server.
Code:
if (ENVIRONMENT != 'development') {  
$smtp_host = '****';
$smtp_user = '****@downundr.com';
$smtp_pass = '****';
$smtp_proto = 'mail';
$nl = '\n';
define ('email_from', '[email protected]');
define ('test_email', '');
} else {
$smtp_host = 'ssl://smtp.googlemail.com';
$smtp_user = '****@gmail.com';
$smtp_pass = '****';
$smtp_proto = 'smtp';
$nl = '\r\n';
define ('email_from', '[email protected]');
define ('test_email', '****@gmail.com');
}
$config = array(  
'useragent'        => 'myUserAg',        
'protocol'         => $smtp_proto,
'mailpath'         => '',
'smtp_host'        => $smtp_host,
'smtp_user'        => $smtp_user,
'smtp_pass'        => $smtp_pass,
'smtp_port'        => 465,
'smtp_timeout'     => 30,
'wordwrap'         => TRUE,
'wrapchars'        => 76,
'mailtype'         => 'text',
'charset'          => 'utf-8',
'validate'         => FALSE,
'priority'         => 3,
'crlf'             => "\r\n",
'newline'          => $nl,
'bcc_batch_mode'   => FALSE,
'bcc_batch_size'   => 200
);

And this is the email helper file:
Code:
function send_account_activation_code($email, $activationCode){
$CI =& get_instance();
$CI->load->library('email');
$CI->load->helper('emails/z_email_footer_text');

$CI->email->from(email_from, 'www.downundr.com');
$CI->email->to((test_email != '')?test_email:$email);
$CI->email->subject('Account Activation Code - www.downundr.com');

$emailMessage =
"Thank you for signing up to www.downundr.com!
blah blah blah blah
".email_footer_text();

$CI->email->message($emailMessage);
$CI->email->send();
}

I'm working on localhost, with it mapped to a domain name, www.localdownundr.com
When running from my test/stage server, which is using a real live email server, it works fine, the email sends, it's just locally that I've started to have this problem.


This is driving me NUTS... been trying to debug this for almost 5 hours now, any help at this stage would be greatly appreciated!!!
#2

[eluser]TheFuzzy0ne[/eluser]
You should probably ask your Web host. It's possible that they are blocking outgoing communications on that port.

It might also be worth trying to send on port 25, although some Web hosts block outgoing communications on this port.

Also, have a play with Telnet, and go through the process to see what's happening. If you've been sending a lot of mail, or you're on a shared server, it's possible that Google have blocked the IP address of your server.
#3

[eluser]TheFuzzy0ne[/eluser]
You can probably ignore the message above. I thought you were having trouble with the live server, but it seems you're having trouble sending from your localhost.

If it's working on your live server, can you not just use those SMTP settings on your localhost?
#4

[eluser]boltsabre[/eluser]
Hey thanks for the input TheFuzzyOne, appreciated!

You're right, I could just change my settings to my online server, but for a range of reasons I like to have a completely isolated setup for my local/development area.

Testing such things as bulk email cron jobs, etc, I'd much prefer to crash/over-burden/whatever my gmail account than my online email server if I happen to botch something up.

And more importantly, I don't like breaking something (the gmail used to work), and then just walk away with some hack fix, it's not a good habit to get into... however, due to time restraints (trying to launch the website this sunday) I might just have to do that for now and revisit this issue after launch.

I'm wondering if perhaps it's this line of code:
Code:
'email_from', '[email protected]'

I understand google stopped making google apps a free service in Dec 2012, perhaps this is causing the issue, what do other people use when sending emails from a gmail account?

I'll have a play around tonight when I get home from work.
#5

[eluser]TheFuzzy0ne[/eluser]
When I signed up for my broadband, I was given an email address by my ISP. That's what I use when I'm developing. I don't bother with Web-based clients because of the problems you're having now. I've had problems in the past, and changes to the service seem to happen far too regularly for my liking.

There are lots of free SMTP services out there. I can't recommend any, but you might find it a lot more straight forward than GMail. I would be tempted to give http://www.gmx.com a try. They're run by 1&1 - a fairly reputable company.
#6

[eluser]boltsabre[/eluser]
Great, thanks for that, I'll give it a shot tonight!!!
#7

[eluser]boltsabre[/eluser]
So... after 10 hours spread out over 2 nights, I fixed it... have a look at the code below

Code:
if (ENVIRONMENT != 'development') {  
$smtp_host = '****';
$smtp_user = '****@downundr.com';
$smtp_pass = '****';
$smtp_proto = 'mail';
$nl = '\n';
define ('email_from', '[email protected]');
define ('test_email', '');
} else {
$smtp_host = 'ssl://smtp.googlemail.com';
$smtp_user = '****@gmail.com';
$smtp_pass = '****';
$smtp_proto = 'smtp';
$nl = '\r\n';
define ('email_from', '[email protected]');
define ('test_email', '****@gmail.com');
}

Notice the new line variable, $nl.... single quotes, not double quotes... this is why I love web development... someone please shoot me!
#8

[eluser]TheFuzzy0ne[/eluser]
I only really glanced at your code, because when you said it worked before, and then stopped working, I assumed it would have been down to a change in environment, not an error in your code. I'm stilled confused as to how that ever worked to begin with.

I'm glad you finally figured it out. I think it's safe to say we both learnt something from this experience.

[quote author="boltsabre" date="1363817288"]someone please shoot me![/quote]

Gladly. I have a contract out on your head as we speak! Wink

But I just drank all the beer so I'm going to have to pay the assassin in Oreos... D:
#9

[eluser]boltsabre[/eluser]
Quote: because when you said it worked before, and then stopped working,.... I’m stilled confused as to how that ever worked to begin with.
I could have, and should have, worded that a little better. It was originally working, with just a single hard coded config array just for gmail.

Then I added the environment related stuff, creating variables and putting them into the config array... bad me used a bunch of copy and pastes, that's how I ended up with single quotes and broke it.

However, it'd been several months since I'd done anything related to sending emails (I've been working on content), and I made the assumption that it was something that had changed with gmail, rather than a bug in my code when my error logs were not showing anything errors and when I'd checked against the files previous version and could see no difference with my gmail settings (apart from those pesky quotes!). At that stage I was like "hmmm, no php errors, same email settings, can't be me, must be them"... how wrong I was ;-)

Yes, valuable lessons to be learnt, many of them! A painful 10 hours of my life gone, but much the wiser for the experience!




Theme © iAndrew 2016 - Forum software by © MyBB