CakeEmail problems on server

2019-04-12 20:06发布

I'm using cakeEmail for simple form and on localhost it worked great, but on server(hosting) It shows me this error:

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)

I have no idea where is the problem.

my 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.'));
    }
}

and view 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();

I tried to call on my hosting helplink and they have no idea but says that PHPMailer works. Im new with cakePHP so Im having problems with moving it on server. Can anyone elp please? Im really deep in this problem.

Thank you

1条回答
【Aperson】
2楼-- · 2019-04-12 20:24

Probable Causes:

  1. Does the server your running from have a spam block on its IP addresses? Chances are the SMTP server is not permitting the connection from your hosting server. Thus the error CONNECTION REFUSED. It is not something on the server you are running the code from, but the server you are trying to log in to.

  2. The SMTP credentials are not correct. Maybe there is something missing. Try connecting using those credentials from another location to see if you can actually connect.

  3. Are the SMTP credentials for the same host you are running from. Maybe the host doesn't permit the outbound connection to SMTP to prevent their servers from being used as a spam sending machine.

Possible Solutions

If none of the probably causes are the culprit, maybe there is a problem with the configuration. You have this:

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,
);

Try simplifying it and changing it to the bare minimums:

public $default = array(
    'transport' => 'Smtp',
    'host' => 'smtp.savana.cz',
    'port' => 25,
    'username' => 'info@olvi.cz',
    'password' => '****',
);
查看更多
登录 后发表回答