电子邮件由cakePHP发送,如何从变量设置管理员电子邮件地址?

时间:2015-12-17 14:26:36

标签: php mysql cakephp

我写了一个注册功能,注册后我想从管理员邮箱地址发送一封电子邮件。如何在变量中设置管理员电子邮件地址?

这是我的功能:

function registration() {
        $this->loadModel('User');
        $this->loadModel('Role');
        if ($this->request->is('post')) {
            $this->User->set($this->request->data);
            if ($this->User->validates()) {
    $mail_data = $this->User->save($this->request->data);


                $owneremail = $this->request->data['info@gmail.com'];
                $from = $owneremail;
                $subject = "Technician registration";
                $user_name = $mail_data['User']['name'];
                $email_user = $mail_data['User']['email'];
                $password = $this->request->data['User']['password'];
                $to = array($mail_data['User']['email']);
                $mail_content = __('Name:', 'beopen') . $user_name . PHP_EOL .
                        __('Email:', 'beopen') . $email_user . PHP_EOL .
                        __('Password:', 'beopen') . $password . PHP_EOL .
                        __($url = Router::url(array("controller" => "users", "action" => "login"), true));

                sendEmail($from, $user_name, $to, $subject, $mail_content);

 $msg = '<div class="alert alert-success">
   <button type="button" class="close" data-dismiss="alert">&times;</button>
   <strong> User Created succeesfully </strong>
   </div>';
            } else {
                $msg = $this->generateError($this->User->validationErrors);
            }
            $this->Session->setFlash($msg);
            // return $this->redirect('create');
        }
        $this->set('roles', $this->Role->find("list"));
    }

通过此代码,我无法从管理员邮件地址发送电子邮件

1 个答案:

答案 0 :(得分:1)

打印数组:$this->request->data。我认为没有像info@gmail.com这样的索引。您似乎尝试在from属性中设置电子邮件。所以只需将电子邮件分配给$ from。试试这个:

第1步:删除$owneremail = $this->request->data['info@gmail.com'];

第2步:将$from = $owneremail;更改为

  $from = 'info@gmail.com';

N.B:研究基本的数组并设置真实的电子邮件以测试电子邮件功能。