-2

每个可以帮助我的人,我是 CakePHP 的新手,我的联系表格有问题,我按照本教程http://blog.jandorsman.com/2011/05/cakephp-contact-form-with-validation-rules/

但是我的收件箱是空的 :( 我收到了消息:您的消息已发送。谢谢,我们会尽快回复您。但是,没有效果 :(.. 有什么问题?

我的控制器:

<?php
class ContactsController extends AppController {
 var $components = array('Email');


 var $helpers = array('Html', 'Form');
    function send() {



        if(!empty($this->data)) {
            $this->Contact->set($this->data);

            if($this->Contact->validates()) {
                if(!empty($this->data['Contact']['company'])) {
                    $this->Email->from = $this->data['Contact']['company'] . ' - ' . $this->data['Contact']['name'] . ' <' . $this->data['Contact']['email'] . '>';
                } else {
                    $this->Email->from = $this->data['Contact']['name'] . ' <' . $this->data['Contact']['email'] . '>';
                }
                $this->Email->to = 'info@mycompany.com';
                $this->Email->subject = 'Website request';
                $this->Email->send($this->data['Contact']['message']);
                $this->Session->setFlash('Your message has been sent.');
                // Display the success.ctp page instead of the form again
                $this->render('success');
            } else {
                $this->render('index');
            }
        }
    }

    public function index() {
        // Placeholder for index. No actual action here, everything is submitted to the send function.
    }
}


?>
4

2 回答 2

0

也许来晚了,你开始了,但你需要添加组件电子邮件和会话

class ContactsController extends Controller {

var $components = array('Email', 'Session');

function send() {
    if(!empty($this->data)) {
        $this->Contact->set($this->data);

......

......

......

检查设置并启用模板的使用:/app/Config/email.php

在“默认”设置中输入您的真实电子邮件地址以测试是否正常工作!

于 2013-04-14T15:43:11.870 回答
0

你应该检查邮件是否真的发送了任何东西。

if ($this->Email->send($this->data['Contact']['message'])) {
    // sent
} else {
    // not sent
    debug($this->Email);
    exit;
}

您只是检查记录是否已保存。您还可以将电子邮件组件置于调试模式以获取更多详细信息。

于 2013-01-04T01:39:17.373 回答