我试图在从 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>
有人可以帮我找出为什么它只发生在服务器上而不是本地主机上吗?