服务器上的CakeEmail问题

时间:2013-12-15 13:25:52

标签: php cakephp cakephp-2.0

我正在使用cakeEmail用于简单的表单,在localhost上它工作得很好,但在服务器上(托管)它显示了这个错误:

CONNECTION REFUSED
Error: An Internal Error Has Occurred.
Stack Trace

CORE/Cake/Network/Email/SmtpTransport.php line 101 → CakeSocket->connect()
CORE/Cake/Network/Email/SmtpTransport.php line 61 → SmtpTransport->_connect()
CORE/Cake/Network/Email/CakeEmail.php line 1124 → SmtpTransport->send(CakeEmail)
APP/Controller/ProductsController.php line 26 → CakeEmail->send(string)
[internal function] → ProductsController->email()
CORE/Cake/Controller/Controller.php line 490 → ReflectionMethod->invokeArgs(ProductsController, array)
CORE/Cake/Routing/Dispatcher.php line 187 → Controller->invokeAction(CakeRequest)
CORE/Cake/Routing/Dispatcher.php line 162 → Dispatcher->_invoke(ProductsController, CakeRequest, CakeResponse)
APP/webroot/index.php line 111 → Dispatcher->dispatch(CakeRequest, CakeResponse)

我不知道问题出在哪里。

我的Config / email.php:

public $default = array(
        'transport' => 'Smtp',
        'from' => array('info@olvi.cz' => 'My Site'),
        'host' => 'smtp.savana.cz',
        'port' => 25,
        'timeout' => 30,
        'username' => 'info@olvi.cz',
        'password' => '****',
        'client' => null,
        'log' => false,
);

My ProductsController.php:

public function email(){
    App::uses('CakeEmail', 'Network/Email');
    if ($this->request->is('post')) {
        $email = new CakeEmail('default');
        $email->from(array('info@olvi.cz' => $this->request->data['Email']['name']));
        $email->to($this->request->data['Email']['sender']);
        $email->subject($this->request->data['Email']['name']);
        $email->send($this->request->data['Email']['message']);
        $this->Session->setFlash(__('Zpráva byla odeslána.'));
    }
}

并查看email.ctp:

echo $this->Form->create('Email');
echo $this->Form->input('name',array('label' => 'Jméno', 'required' => 'required'));
echo $this->Form->input('sender',array('type' => 'email','label' => 'Váš e-mail', 'required' => 'required'));
echo $this->Form->input('message', array('type' => 'textarea', 'label' => 'Zpráva', 'required' => 'required'));
echo $this->Form->submit('Odeslat', array('id' => 'button', 'div' => false));
echo $this->Form->end();

我试图调用我的托管帮助链接,他们不知道但是说PHPMailer工作。 我是cakePHP的新手,所以我在服务器上移动它有问题。任何人都可以吗?我真的很深入这个问题。

谢谢

1 个答案:

答案 0 :(得分:2)

可能原因:

  1. 您运行的服务器的IP地址是否有垃圾邮件阻止?有可能SMTP服务器不允许从您的托管服务器进行连接。因此错误CONNECTION REFUSED。服务器上没有运行代码的东西,而是您尝试登录的服务器。

  2. SMTP凭据不正确。也许有些东西不见了。尝试使用其他位置的凭据进行连接,看看您是否可以实际连接。

  3. 您运行的同一主机的SMTP凭据。也许主机不允许与SMTP的出站连接,以防止他们的服务器被用作垃圾邮件发送机。

  4. 可能的解决方案

    如果没有可能的原因是罪魁祸首,可能是配置有问题。你有这个:

    public $default = array(
        'transport' => 'Smtp',
        'from' => array('info@olvi.cz' => 'My Site'),
        'host' => 'smtp.savana.cz',
        'port' => 25,
        'timeout' => 30,
        'username' => 'info@olvi.cz',
        'password' => '****',
        'client' => null,
        'log' => false,
    );
    

    尝试简化并将其更改为最低限度:

    public $default = array(
        'transport' => 'Smtp',
        'host' => 'smtp.savana.cz',
        'port' => 25,
        'username' => 'info@olvi.cz',
        'password' => '****',
    );