Zend Mail 不断给我一个套接字错误

发布于 2024-11-01 09:37:20 字数 2090 浏览 0 评论 0原文

我在使用 zend 框架发送电子邮件时遇到问题。我不断收到“无法打开套接字”错误。

我不知道这里出了什么问题 - 它曾经在我的另一台主机上工作。自从我将其转移到另一台主机后,我无法发送电子邮件。我已设置配置值以匹配新的电子邮件服务器。

这是我的代码:

$config = array('auth' => _config('mail', 'auth'),
        'username' => _config('mail', 'email'),
        'password' => _config('mail', 'password'));

$tr = new Zend_Mail_Transport_Smtp(_config('mail', 'smtp'), $config);

$mail = new Zend_Mail();
$mail->setDefaultTransport($tr);

$mail->setFrom(_config('mail','email'), _config('mail','name'));
$mail->addTo($account_email);

$mail->setSubject($mailTitle);
$mail->setBodyText($mailContent);
$mail->send($tr);

EDIt ===

那么上面发布的代码是我的实际代码 - 我不知道它有什么问题,因为它曾经在另一台主机上工作。

以下是我收到的确切错误

Could not open socketstring(1237) "#0 /home/india/public_html/demo/library/Zend/Mail/Protocol/Smtp.php(167): Zend_Mail_Protocol_Abstract->_connect('tcp://mail.indi...') 
#1 /home/india/public_html/demo/library/Zend/Mail/Transport/Smtp.php(199): Zend_Mail_Protocol_Smtp->connect() 
#2 /home/india/public_html/demo/library/Zend/Mail/Transport/Abstract.php(348): Zend_Mail_Transport_Smtp->_sendMail() 
#3 /home/india/public_html/demo/library/Zend/Mail.php(1194): Zend_Mail_Transport_Abstract->send(Object(Zend_Mail)) 
#4 /home/india/public_html/demo/application/controllers/AccountController.php(2153): Zend_Mail->send(Object(Zend_Mail_Transport_Smtp)) 
#5 /home/india/public_html/demo/library/Zend/Controller/Action.php(513): AccountController->forgetPasswordAction() 
#6 /home/india/public_html/demo/library/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('forgetPasswordA...') 
#7 /home/india/public_html/demo/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) 
#8 /home/india/public_html/demo/application/bootstrap.php(26): Zend_Controller_Front->dispatch() #9 /home/india/public_html/demo/html/index.php(4): Bootstrap::run() #10 {main}" 

I'm having trouble with sending email using the zend framework. I keep getting a "Could not open socket" error.

I don't know whats wrong here - it used to work on my other host. Ever since I shifted it to another host I can't send emails. I've set up the configuration values to match the new email server.

Heres my code:

$config = array('auth' => _config('mail', 'auth'),
        'username' => _config('mail', 'email'),
        'password' => _config('mail', 'password'));

$tr = new Zend_Mail_Transport_Smtp(_config('mail', 'smtp'), $config);

$mail = new Zend_Mail();
$mail->setDefaultTransport($tr);

$mail->setFrom(_config('mail','email'), _config('mail','name'));
$mail->addTo($account_email);

$mail->setSubject($mailTitle);
$mail->setBodyText($mailContent);
$mail->send($tr);

EDIt ===

Well the code posted above is my actual code - I don't know whats wrong with it as it used to work on another host.

The following is the exact error I'm getting

Could not open socketstring(1237) "#0 /home/india/public_html/demo/library/Zend/Mail/Protocol/Smtp.php(167): Zend_Mail_Protocol_Abstract->_connect('tcp://mail.indi...') 
#1 /home/india/public_html/demo/library/Zend/Mail/Transport/Smtp.php(199): Zend_Mail_Protocol_Smtp->connect() 
#2 /home/india/public_html/demo/library/Zend/Mail/Transport/Abstract.php(348): Zend_Mail_Transport_Smtp->_sendMail() 
#3 /home/india/public_html/demo/library/Zend/Mail.php(1194): Zend_Mail_Transport_Abstract->send(Object(Zend_Mail)) 
#4 /home/india/public_html/demo/application/controllers/AccountController.php(2153): Zend_Mail->send(Object(Zend_Mail_Transport_Smtp)) 
#5 /home/india/public_html/demo/library/Zend/Controller/Action.php(513): AccountController->forgetPasswordAction() 
#6 /home/india/public_html/demo/library/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('forgetPasswordA...') 
#7 /home/india/public_html/demo/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) 
#8 /home/india/public_html/demo/application/bootstrap.php(26): Zend_Controller_Front->dispatch() #9 /home/india/public_html/demo/html/index.php(4): Bootstrap::run() #10 {main}" 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

闻呓 2024-11-08 09:37:20

玛哈巴·阿里! ,
挖掘 Zend mail 的代码显示 http: //framework.zend.com/svn/framework/standard/trunk/library/Zend/Mail/Protocol/Abstract.php

 protected function _connect($remote)
    {
        $errorNum = 0;
        $errorStr = '';

        // open connection
        $this->_socket = @stream_socket_client($remote, $errorNum, $errorStr, self::TIMEOUT_CONNECTION);

        if ($this->_socket === false) {
            if ($errorNum == 0) {
                $errorStr = 'Could not open socket';
            }
            /**
             * @see Zend_Mail_Protocol_Exception
             */
            require_once 'Zend/Mail/Protocol/Exception.php';
            throw new Zend_Mail_Protocol_Exception($errorStr);
        }

        if (($result = $this->_setStreamTimeout(self::TIMEOUT_CONNECTION)) === false) {
            /**
             * @see Zend_Mail_Protocol_Exception
             */
            require_once 'Zend/Mail/Protocol/Exception.php';
            throw new Zend_Mail_Protocol_Exception('Could not set stream timeout');
        }

        return $result;
    }

通常错误号为 0,因为

  if ($errorNum == 0) {
                    $errorStr = 'Could not open socket';
               }

from : http://php.net/manual/en/function.stream-socket-client.php

失败时显示 errno 和 errstr
参数将填充为
实际系统级错误
发生在系统级connect()
称呼。如果errno中返回的值
为 0 并且函数返回 FALSE,
这表明错误
发生在 connect() 调用之前。
这很可能是由于问题造成的
初始化套接字。请注意,
errno 和 errstr 参数将始终
通过引用传递。

我猜是某些防火墙阻止了发送的连接,
系统级或网络级错误

如果您使用更详细的信息更新您的答案,我很乐意提供帮助

marhaba Ali! ,
digging the code of Zend mail shows http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Mail/Protocol/Abstract.php

 protected function _connect($remote)
    {
        $errorNum = 0;
        $errorStr = '';

        // open connection
        $this->_socket = @stream_socket_client($remote, $errorNum, $errorStr, self::TIMEOUT_CONNECTION);

        if ($this->_socket === false) {
            if ($errorNum == 0) {
                $errorStr = 'Could not open socket';
            }
            /**
             * @see Zend_Mail_Protocol_Exception
             */
            require_once 'Zend/Mail/Protocol/Exception.php';
            throw new Zend_Mail_Protocol_Exception($errorStr);
        }

        if (($result = $this->_setStreamTimeout(self::TIMEOUT_CONNECTION)) === false) {
            /**
             * @see Zend_Mail_Protocol_Exception
             */
            require_once 'Zend/Mail/Protocol/Exception.php';
            throw new Zend_Mail_Protocol_Exception('Could not set stream timeout');
        }

        return $result;
    }

and usually the error number 0 because of

  if ($errorNum == 0) {
                    $errorStr = 'Could not open socket';
               }

from : http://php.net/manual/en/function.stream-socket-client.php

On failure the errno and errstr
arguments will be populated with the
actual system level error that
occurred in the system-level connect()
call. If the value returned in errno
is 0 and the function returned FALSE,
it is an indication that the error
occurred before the connect() call.
This is most likely due to a problem
initializing the socket. Note that the
errno and errstr arguments will always
be passed by reference.

I guess its some firewall blocking the connection to be sent out ,
system-level or network-level error

If you update your answer with more detailed info , i would be happy to help

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文