【问题标题】:Send a mail with Zend Framework : "Connection could not be established"使用 Zend Framework 发送邮件:“无法建立连接”
【发布时间】:2013-04-25 15:09:43
【问题描述】:

我现在正在开发一个“旧”的 php/zend 项目。我是在本地安装的,除了用户填写表单后应用程序发送确认邮件的部分外,一切都很好。

我遇到的错误基本上是“无法建立连接”

这是代码:

公共函数 sendMail($user, $gain=null) { 全局 $config;

$this->_view->url   = $config->app->url;

$tr = new Zend_Mail_Transport_Smtp($config->app->mail->server);
Zend_Mail::setDefaultTransport($tr);

$mail = new MGMail($config->app->mail->key, true);
$mail->setFrom($config->app->mail->from, $config->app->mail->fromName);

if ($gain == null)
{
    $object = $config->app->mail->object->inscription;
    $render = $this->_view->render('inscription.phtml');
}
else
{
    switch ($gain)
    {
        case 'peignoir':
            $gain_name = 'un '.$gain;
        case 'casquette':
            $gain_name = 'une '.$gain;
    }

    $object = sprintf($config->app->mail->object->gain, $gain_name);
    $render = $this->_view->render($gain.'.phtml');
}

$mail->setSubject($object);
$mail->addTo($user->email, $user->first_name.' '.$user->last_name);
$mail->setBodyText($render);

$mail->send();

$this->saveSendEmail($object, $render, $user);

}

$config->app->mail->server

在我的 application.ini 中仅包含“localhost”

我需要做什么来解决这个问题? 有没有要激活的php模块? 对不起,如果这对你来说很明显,我已经很长时间没有研究这个了......

【问题讨论】:

  • 是本地机器运行 SMTP 服务器并且服务正在运行吗?你能在 SMTP 端口上远程登录到 localhost 吗?
  • 我刚刚做到了:“无法建立连接”我该如何激活它?

标签: php zend-framework smtp sendmail


【解决方案1】:

确保您正在使用的机器上本地运行 SMTP 服务。您可以使用 telnet 到 localhost 的 25 端口来检查这一点:

远程登录本地主机 25

如果超时,则很可能您没有安装或运行 SMTP 服务器:

C:\Users\用户名>telnet localhost 25 连接到 localhost...无法在端口 25 上打开与主机的连接:连接失败

那是你的问题。

要解决它,您需要安装和配置邮件服务器。我过去使用过 hmailserver (www.hmailserver.com),它运行良好。

【讨论】:

  • 我刚刚做到了:“无法建立连接”我该如何激活它?
  • 安装和配置邮件服务器,例如hmailserver (hmailserver.com)
  • 配置hmailserver不需要smtp认证。
猜你喜欢
  • 2020-07-30
  • 2012-02-19
  • 1970-01-01
  • 2017-07-28
  • 2011-01-17
  • 1970-01-01
  • 2015-02-14
  • 2015-11-08
  • 2017-01-18
相关资源
最近更新 更多