Cakephp 发送邮件

Cakephp send mail

我正在使用 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()
{ 

}


}

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

 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'));
      }
    }

 }

你也可以看到我的答案写蛋糕的形式php