简体   繁体   English

Cakephp SMTP电子邮件不起作用

[英]Cakephp smtp emails not working

I'm using Cakephp 2.6, I have configured smtp settings as follows in email.php, 我使用的是Cakephp 2.6,我已经在email.php中配置了smtp设置,

 public $smtp = array(
    'transport' => 'Smtp',
    'from' => array('support@mywebsite.com'=> 'MYWEBSITE'),
    'host' => 'hostingserver',
    'port' => 587,
    'username' => 'username',
    'password' => 'password',
    'client' => null,
    'log' => false,
    'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true
    )
);

In Controllerfunction 在控制器功能中

    $email = "myemail";
    $Email = new CakeEmail("smtp");
    $Email->helpers('Html', 'Form', 'Text');
    $Email->emailFormat('html')
            ->subject('SUB: Notification')
            ->to($email)
            ->from('fromemail', 'MYWEBSITE')
            ->send('My message');

This is the ERROR I'm getting, 这是我得到的错误

Internal error occured

Stack Trace

CORE/Cake/Network/Email/SmtpTransport.php line 154 → CakeSocket->connect()
CORE/Cake/Network/Email/SmtpTransport.php line 95 → SmtpTransport->_connect()
CORE/Cake/Network/Email/CakeEmail.php line 1161 → SmtpTransport->send(CakeEmail)
APP/Plugin/Admin/Controller/ClientsController.php line 816 → CakeEmail->send(string)
[internal function] → ClientsController->sendemail()
CORE/Cake/Controller/Controller.php line 490 → ReflectionMethod->invokeArgs(ClientsController, array)
CORE/Cake/Routing/Dispatcher.php line 193 → Controller->invokeAction(CakeRequest)
CORE/Cake/Routing/Dispatcher.php line 167 → Dispatcher->_invoke(ClientsController, CakeRequest)
APP/webroot/index.php line 118 → Dispatcher->dispatch(CakeRequest, CakeResponse)

Where I'm missing configuration, any help is much appreciated. 在我缺少配置的地方,我们将不胜感激。

The problem occurs because the SSL verification goes wrong - as the error message indicates. 发生问题是因为SSL验证出错-如错误消息所示。 Ideally, you should set up the SSL certificate, but you can disable ssl certificate verification as an alternative, although this is less secure. 理想情况下,您应该设置SSL证书,但是您可以禁用ssl证书验证,尽管这种方法不太安全。

You tried to disable ssl by adding the ssl array directly, but as this post points out, the ssl array needs to be wrapped in the context array like this: 您试图通过直接添加ssl数组来禁用ssl,但是正如这篇文章指出的那样,ssl数组需要像这样包装在context数组中:

'context'=>array(
    'ssl' => array( 
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
)

That fixed the problem for me. 那为我解决了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM