Wednesday, June 19, 2013

Fixing localhost email on CodeIgniter under Windows

Argh. After spending a LOT of agonizing hours trying to get localhost email to work under CodeIgniter (PHP) on my Windows 7 machine, I finally figured it out. And since this is such a non-intuitive fix, hopefully I can ease the pain for someone else by sharing this.

Setup:
  • Using XAMPP + CodeIgniter
  • I had my email.php configured as very standard for localhost
    • $config['protocol']  = 'smtp';
    • $config['smtp_host'] = 'localhost';
    • $config['smtp_port'] = '25';
    • $config['smtp_timeout']='10';

Issue:
  • My PHP code kept hanging in "$this->email->send()" giving me a "waiting for localhost".
  • In my php_error_log I had "Fatal error: Maximum execution time of 300 seconds exceeded in [stuff]\system\libraries\Email.php on line 1869


Resolution:
  • Turns out that you need to specify the newlines on Windows
  • Simply update your email.php to include:
    • $config['newline'] = "\r\n";
    • $config['crlf'] = "\r\n";
  • Some additional details at the end of this thread http://ellislab.com/forums/viewthread/184596/

That's it.
Nifty

2 comments:

Robert Cosgrove said...

That was my issue, thanks!

redevil said...

This totally helped me. It works on Mac too.