本文介绍了CakeEmail未发送,但没有错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对CakePHP还是很陌生,这是我第一次尝试建立电子邮件表单.

I'm pretty new to CakePHP and this is my first attempt setting up an email form.

使示例保持简单:

<?php
App::uses('AppController', 'Controller');
App::uses('CakeEmail', 'Network/Email');
class EmailController extends AppController {

    public function send_email($from, $subject, $message) {
        $Email = new CakeEmail();
        $Email->from($from)
        ->to('[my personal email]')
        ->subject($subject);
        if($Email->send($message)) {
            $result = 'Your email has been sent.';
        } else {
            $result = 'Your email failed to send.';
        }

        $this->set('result', $result);
        $this->set('params', '('.$from.'|'.$subject.'|'.$message.')');
    }
}

send_email.ctp

send_email.ctp

<?php echo $result;?>
<br>
<?php echo $params;?>

我收到您的电子邮件已发送.",$ params符合我的预期,并且没有看到任何错误...但是我没有收到电子邮件.知道为什么会发生这种情况吗?

I'm getting "Your email has been sent.", the $params look as I expect, and I am not seeing any errors... but I'm not getting the email. Any idea why this might happen?

推荐答案

在此之前,您需要在config文件夹下的email.php中定义电子邮件配置

Before this you need to define Email configuration in email.php under Config folder

例如,这里有gmail配置

Here we have gmail configuration for example

class EmailConfig {
    public $gmail = array(
        'host' => 'ssl://smtp.gmail.com',
        'port' => 465,
        'username' => '[email protected]',
        'password' => '*****',
        'transport' => 'Smtp'
    );
}

然后您可以在控制器中使用此设置,例如

then you can use this setting in controller like

$Email= new CakeEmail('gmail');

简而言之,您必须根据要求配置SMTP.我希望这对您会很方便.谢谢

Inshort you have to configure SMTP according to requirement. I hope this will be handy for you. Thanks

这篇关于CakeEmail未发送,但没有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 17:49