Developer
Developer

Reputation: 1040

Codeigniter send mail working in localhost but not in server

What I am trying

I am building a codeigniter application and need to send mail. My mail configuration works perfectly when I try to send mail from localhost. But its not working when host it on server.

Mail Config

var $useragent      = "CodeIgniter";
var $mailpath       = "/usr/sbin/sendmail"; // Sendmail path
var $protocol       = "smtp";   // mail/sendmail/smtp
var $smtp_host      = "send.one.com";       // SMTP Server.  Example: mail.earthlink.net
var $smtp_user      = "[email protected]";        // SMTP Username
var $smtp_pass      = "pass";       // SMTP Password
var $smtp_port      = "25";     // SMTP Port
var $smtp_timeout   = 60;       // SMTP Timeout in seconds
var $smtp_crypto    = "";       // SMTP Encryption. Can be null, tls or ssl.
var $wordwrap       = TRUE;     // TRUE/FALSE  Turns word-wrap on/off
var $wrapchars      = "76";     // Number of characters to wrap at.
var $mailtype       = "html";   // text/html  Defines email formatting
var $charset        = "utf-8";  // Default char set: iso-8859-1 or us-ascii
var $multipart      = "mixed";  // "mixed" (in the body) or "related" (separate)
var    $alt_message         = '';       // Alternative message for HTML emails
var $validate       = FALSE;    // TRUE/FALSE.  Enables email validation
var $priority       = "1";      // Default priority (1 - 5)
var $newline        = "\r\n";       // Default newline. "\r\n" or "\n" (Use "\r\n" to comply with RFC 822)
var $crlf           = "\r\n";

I am getting the following error while sending from server

 A PHP Error was encountered

 Severity: Warning

 Message: fsockopen(): unable to connect to send.one.com:25 (Connection timed out)

 Filename: libraries/Email.php

 Line Number: 1689

The application is hosted at one.com

Upvotes: 1

Views: 2522

Answers (2)

heySushil
heySushil

Reputation: 499

I'm also looking for the solution and most of the time every thing going great on localhost but on server just hell every thing. But after many try one thing I understand as per different servers like - Godaddy, Plesk, Hostinger etc... It's a game of protocole and port number like -

var $protocol  = "smtp";
var $protocol  = "tls";
var $protocol  = "imps";
var $protocol  = "mail";
var $protocol  = "sendmail";

Same for port -

var $smtp_port = "25"; //It works most of time on localhost
var $smtp_port = "465"; //For gmail
var $smtp_port = "587"; // Sometime work for gmail and for others
var $smtp_port = "995"; // On few cases

Also there is some cases of smtp user

var $smtp_user  = "ssl://smtp.gmail.com";
var $smtp_user  = "ssl://smtp.googlemail.com";
var $smtp_user  = "tls://smtp.yourmail.com";
var $smtp_user  = "imps://smtp.yourmail.com";
var $smtp_user  = "smtp.gmail.com";
var $smtp_user  = "smtp.googlemail.com";

But most of servers not allow ssl:// or all other prefix they direct want the email address. Yes it's to confuging but it's ture to configer email on server it's like milestone for first time user on server but after that you know how things going on server and you will easiely find your soluton or not. But good luck.

Upvotes: 0

Avinash
Avinash

Reputation: 2005

I had the same problem. After trying several times and failing to find a solution, I changed my protocol to mail. If you are changing the email protocol you may recieve the following error:

A PHP Error was encountered
Severity: Warning
Message: mail(): Policy restriction in effect. The fifth parameter is disabled on this system
Filename: libraries/Email.php
Line Number: 1537

Just change the code at /system/libraries/email.php in function _send_with_mail()

from

if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From']))) 

to

if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str)) 

because of: “// most documentation of sendmail using the “-f” flag lacks a space after it, however // we’ve encountered servers that seem to require it to be in place.”

Hope someone can give a solution for sending mail using smtp.

Upvotes: 1

Related Questions