CakePHP传递变量以使用CakeEmail发送电子邮件

时间:2012-09-19 02:53:44

标签: email cakephp

在CakePHP 2.x中,如何在表单中创建变量以将其传递给CakeEmail函数?

我目前有一个php文件'email.php',其中包含一个输入'to','subject'和'message'的表单。此表单传递给名为“email_send.php”的文件,我无法获得要传递的输入。

这是'email.php'代码;

<?php $this->Html->addCrumb('New Email', '#'); ?>

<div id="email_page" class="span12">
    <div class="row">

<?php echo $this->Form->create('Email', array('controller'=>'person', 'action'=>'email_send.php'));
    echo $this->Form->input('To: ', array('class'=>'email_form','label'=>'To: ','value'=>$email['Person']['primEmail']));
    echo $this->Form->input('Subject: ', array('class'=>'email_form','label'=>'Subject: '));
    echo $this->Form->input('Message: ', array('class'=>'email_form email_body', 'type'=>'textarea','label'=>'Message: '));
    echo $this->Form->end('Send', array('class'=>'pull-right')); ?>

    </div>
</div>

这是'email_send.php'代码。变量$ to,$ subject和$ message是我放在那里的假设我需要从前一个表单传递这个函数变量。

<?php

$email = new CakeEmail();
$email->from(array('info@info' => 'InfoSite'))
    ->to($to)
    ->subject($subject)
    ->send($message);

?>

以下是有关CakePHP for CakePHP 2.x的文档;

http://book.cakephp.org/2.0/en/core-utility-libraries/email.html

1 个答案:

答案 0 :(得分:0)

<?php
    App::uses('CakeEmail', 'Network/Email');
    $email = new CakeEmail();
    $email->from(array('info@info' => 'InfoSite'))
         ->to($to)
         ->subject($subject)
         ->send($message);

     ?>

阅读我的博客以发送电子邮件:

http://chetan4cake.blogspot.in/2012/07/email-in-cakephp-20.html