【问题标题】:Cakephp send mailCakephp 发送邮件
【发布时间】:2015-12-21 05:59:00
【问题描述】:

我正在使用 cakephp2.4.5,我对 cakephp 完全陌生,谁能帮助我如何在 cakephp 中编写表格以及如何发送邮件

我有这个表格,当用户填写电子邮件和消息框并点击发送邮件时,应该发送带有上述信息的邮件。我什至不知道如何写一个来自请帮助我

包装视图

<?php echo $this->Form->create('Feedback', array('action' => 'sendmail')); ?>
 <?php echo $this->Form->input('mail',array('label' => false,'class'=>'form__in form__in--text form-control','placeholder'=>__('E-mail'),'div'=>false));?>
 <?php echo $this->Form->textarea('message',array('label' => false,'class'=>'form__in form__in--textarea form-control','placeholder'=>__('Message'),'div'=>false));?>
 <?php echo $this->Form->end(array('label' => 'Send', 'class' => 'form__submit', )); ?>

控制器文件

<?php
//App::uses('CakeTime', 'Utility');
class FeedbacksController extends AppController {

public function sendmail()
{ 

}


}

【问题讨论】:

标签: php cakephp cakephp-2.3 cakephp-2.4


【解决方案1】:

在你的控制器文件中试试这个。

 public function sendmail()
 { 
    if ($this->request->is('post')) 
    {
      if ($this->Feedback->save($this->request->data)) //Save form data before sending mail
      {
        //Your Form's fields
        $name = $this->data['Feedback']['name'];
        $email = $this->data['Feedback']['email'];
        $subject = $this->data['Feedback']['subject'];
        $msg = $this->data['Feedback']['message'];
        $to = "recipient@gmail.com";
        $from = $email;
        $headers = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-Type: text/html; charset=UTF-8' . "\r\n";
        $headers .= 'From:' .$from. " ".'<'.$from.'>'."\r\n";
        $headers .= 'Reply-To:'.$from. "\r\n";
        $sent_message = mail($to,$subject,$msg,$headers); //Send mail

      }
      else
      {
        $this->Session->setFlash(__('The contact could not be saved. Please, try again.'), 'default',array('class'=>'errors'));
      }
    }

 }

您也可以在 cake php 中查看我的答案 Uploading image in cakephp and storing it's path in database

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-01-17
  • 1970-01-01
  • 2013-09-06
  • 2011-11-12
  • 2014-12-10
  • 1970-01-01
  • 2013-04-08
  • 2013-04-01
相关资源
最近更新 更多