0

我试图在从 cakephp 中的表单发送电子邮件时显示一条闪存消息,上面写着“已发送邮件”。电子邮件已成功发送给收件人,但随后进入空白屏幕并且不显示表明该消息已发送的 Flash 消息。我检查了控制器中 php 标记前后的空格,但似乎没有成为问题。它在我的本地主机上工作正常并显示消息但不在服务器上。我将把我的控制器代码

public function contact() {

    $email = new CakeEmail();
    if ($this->request->is('post')) {
        $this->Contact->set($this->request->data);
        if ($this->Contact->save($this->request->data)) {
            //$this->Project->set($this->data)
            $name = $this->request->data['Contact']['name'];
            $mail = $this->request->data['Contact']['email'];
            $email->from(array($mail => $name));
            $email->to('sales@blacknova.com.au');
            if (isset($this->request->data['Contact']['contacttime'])) {
                $ctime = implode(',', $this->request->data['Contact']['contacttime']);
            }
            $message = "Phone No : ".$this->request->data['Contact']['phone']."\n\nBest Contact time :".$ctime." \n\nMessage : ".$this->request->data['Contact']['description'];
            $email->subject('BlackNova Website Contact Form Message');
            //$email->send($message);
            //$success =1;
            //$email->send($this->request->data['Contact']['phone']);
            //pr($message);
            if ($email->send($message)) {
                $this->Session->setFlash('Mail sent successfully');
                $this->redirect(array('controller' => 'BlockContents', 'action' => 'contact'));
                //pr($success);
            }
        }
    }
}

有一个contact.ctp

    <div id="formcontainer_left">
    <?php echo $this->Form->create('Contact'); ?> 
    <div class="inputbox1"><?php echo $this->Form->input('name');?></div><br>
    <div class="inputbox2"><?php echo $this->Form->input('email'); ?></div><br>
    <div class="inputbox3"><?php echo $this->Form->input('phone');?></div><br>
    </div>
    <div id="formcontainer_right">  
    <div id="me"><?php echo $this->Form->input('description');?>
    </div>
    <?php echo $this->Form->submit('SUBMIT');?>

    </div>

      <div  id="formcontainer_xright">

    <div class="formcontainer_last"> BEST TIME TO CONTACT* </div>
    <div id="chkbox">
     <?php echo $this->Form->input('contacttime',array('label'=>false,'type'=>'select','class'=>'checkdiv','multiple'=>'checkbox','options'=>array('Before work' =>'Before work','During work'=>'During work','After work'=>'After work'),'escape'=>false)) ;?> 
    </div>
      </div>
            <?php echo $this->Form->end(); ?>
        <div class="contactformbottom">
    </div>

</div> 

<div id="formcontainer2">
   <p> <?php echo $this->Session->flash();?></p>

有人可以帮我找出为什么它只发生在服务器上而不是本地主机上吗?

4

2 回答 2

0

正如@DavidYell 所说,问题在于重定向中的控制器。如果您确实需要该重定向,他的回答应该可以解决所有问题。我只想指出,如果您只想清除文本框中的值但保持相同的操作,那么您实际上并不需要重定向。

if ($email->send($message)) {
    $this->Session->setFlash('Mail sent successfully');
    $this->request->data = null;
}

应该清除不需要重定向的文本框。

于 2013-05-23T13:59:04.433 回答
0

问题是您BlockContents不是重定向 url 中的有效控制器。

如果您尝试改用下划线版本block_contents,您会发现它可能会起作用。

看看书中推荐的用法。http://book.cakephp.org/2.0/en/getting-started/cakephp-conventions.html#url-considerations-for-controller-names

于 2013-05-23T11:33:49.143 回答