Codeigniter发送邮件在localhost中工作但不在服务器中工作

时间:2014-12-25 07:37:08

标签: codeigniter email

我在尝试什么

我正在构建一个codeigniter应用程序并需要发送邮件。当我尝试从localhost发送邮件时,我的邮件配置工作正常。但是当它在服务器上托管时它不起作用。

邮件配置

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      = "no-reply@domain.com";        // 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";

从服务器发送时出现以下错误

 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

该应用程序在one.com上托管

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。在尝试多次并且未能找到解决方案后,我将协议更改为邮件。如果要更改电子邮件协议,则可能会收到以下错误:

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

只需更改函数_send_with_mail()中/system/libraries/email.php中的代码

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

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

因为:“//然而,大多数使用”-f“标志的sendmail文档都没有空格   //我们遇到了似乎需要它的服务器。“

希望有人可以提供使用smtp发送邮件的解决方案。

答案 1 :(得分:0)

我也在寻找解决方案,并且在大多数情况下,每件事在localhost上都进展顺利,但在服务器上一切都变糟了。但是在尝试了许多不同的服务器后,我了解了一些东西,例如Godaddy,Plesk,Hostinger等。 这是协议和端口号的游戏,例如-

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

与端口相同-

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

还有一些smtp用户的情况

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";

但是大多数服务器不允许ssl://或它们直接指向的所有其他前缀需要电子邮件地址。 是的,这很容易混淆,但是在服务器上配置电子邮件很容易,这对服务器上的首次用户来说是一个里程碑,但是之后您就知道服务器上的情况如何,并且可以轻松地找到自己的解决方案。 但是,祝你好运。