【问题标题】:why email component dont sent activation code to gmail?为什么电子邮件组件不向 gmail 发送激活码?
【发布时间】:2012-01-07 07:05:34
【问题描述】:

我尝试将激活码从本地主机发送到用户邮件(当前为 gmail).. 当提交保存在数据库中的用户信息但消息未发送时..为什么不发送?

var $components = array('Email','Auth','Recaptcha');
// Allows a user to sign up for a new account
    function register () {
        if (!empty($this->data)) {
            // See my previous post if this is forgien to you
  if($this->data['User']['password'] == $this->Auth->password($this->data['User']['password_confirm'])){
                $this->User->data = Sanitize::clean($this->data);
            // Successfully created account - send activation email
        if($this->Recaptcha->valid($this->params['form'])){
            if ($this->User->save()) {
                $this->__sendActivationEmail($this->User->getLastInsertID());
                $this->Session->setFlash('activation code sent check your mail');
                $this->redirect('/users/register');
            }else {
             $this->data['User']['password'] = null;
            }

        }else{
            $this->data['User']['password'] = null;
          $this->Session->setFlash('wrong captcha please try again');
        }
  }else{
      $this->data['User']['password'] = null;
      $this->Session->setFlash('password not match');
  }

    }
   }

此函数向 $user_id 指定的 user.id 发送激活邮件 @param Int $user_id 用户发送激活邮件到 @return Boolean 表示成功

function __sendActivationEmail($user_id) {
        $user = $this->User->find(array('User.id' => $user_id), array('User.id','User.email', 'User.username'), null, false);
        if ($user === false) {
            debug(__METHOD__." failed to retrieve User data for user.id: {$user_id}");
            return false;
        }

        // Set data for the "view" of the Email

        $this->set('activate_url', 'http://' . env('SERVER_NAME') . '/cakenews/users/activate/' . $user['User']['id'] . '/' . $this->User->getActivationHash());
  $this->set('username', $this->data['User']['username']);

        $this->Email->to = $user['User']['email'];
        $this->Email->subject = env('SERVER_NAME') . ' - Please confirm your email address';
        $this->Email->from = 'spcialist@gmail.com';
        $this->Email->template = 'user_confirm';
         $this->Email->delivery = 'smtp';
       $this->Email->smtpOptions = array(
'port'=>'465',
'timeout'=>'30',
'host' => 'ssl://smtp.gmail.com',
'username'=>'spcialist@gmail.com',
'password'=>1234567,

               );
        $this->Email->sendAs = 'text';   // you probably want to use both :)
        return $this->Email->send();
    }

【问题讨论】:

    标签: cakephp cakephp-1.3 cakephp-2.0


    【解决方案1】:

    您写的是您在本地主机上,您可能无法发送电子邮件,但可能会在线工作。

    尝试调试

    function __sendActivationEmail($user_id) {
        $this->Email->delivery = 'debug';
        ....
    }
    

    然后在你的布局中

    <?php echo $this->Session->flash('email'); ?>
    

    看看会发生什么。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-02
      • 2014-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多