javascript - How to send mail confirmation after signup in Cakephp 2 -
hello want send mail after signup , have problem , userscontroller :
public function add() { if ($this->request->is('post')) { $this->user->create(); if ($this->user->save($this->request->data)) { $link = array('controller'=>'users','action'=>'activate', $this->user->id.'-'.md5($this->request->data['user']['password'])); app::uses('cakeemail','network/email'); $mail = new cakeemail(); $mail->from('dafhermcslama@gmail.com') ->to($this->request->data['user']['email']) ->subject('test :: inscription') ->emailformat('html') ->template('signup') ->viewvars(array('username'=>$this->request->data['user']['username'], 'link'=>$link)) ->send(); $this->session->setflash(__('the user has been saved.')); $this->auth->login($this->data); return $this->redirect(array('controller'=>'users','action' => 'index')); //$this->redirect('/users/index'); } else { $this->session->setflash(__('the user not saved. please, try again.')); } } $countries = $this->user->country->find('list'); $cities = $this->user->city->find('list'); $permits = $this->user->permit->find('list'); $this->set(compact('countries', 'cities', 'permits')); $this->set('countries', $this->user->city->country->find('list')); }
and email.php
class emailconfig { public $default = array( 'transport' => 'mail', 'from' => 'dafhermcslama@gmail.com', //'charset' => 'utf-8', //'headercharset' => 'utf-8', );
and php.ini :
[mail function] ; win32 only. ; http://php.net/smtp smtp = smtp.gmail.com ; http://php.net/smtp-port smtp_port = 25 ; win32 only. ; http://php.net/sendmail-from sendmail_from = dafhermcslama@gmail.com ; unix only. may supply arguments (default: "sendmail -t -i"). ; http://php.net/sendmail-path ;sendmail_path = ;sendmail_path="c:\wamp\sendmail\sendmail.exe -t -i" ;sendmail_path = "\"c:\wamp\sendmail\sendmail.exe\" -t"
and view/email/html/signup.ctp
<p> <strong>bonjour <?php echo $username; ?></strong> </p> <p> to activate profile clic here : </p> <p> <?php echo $this->html->link('activate', $this->html->url($link, true)); ?> </p>
but when register message error :
mail(): smtp server response: 530 5.7.0 must issue starttls command first. p1sm178880wib.23 - gsmtp error: internal error has occurred.
what ?
there options missing in email.php
configuration file. gmail should looks like:
public $default = array( 'host' => 'ssl://smtp.gmail.com', 'port' => 465, 'username' => 'my@gmail.com', 'password' => 'secret', 'transport' => 'smtp' );
or if use cakephp 2.3.x+:
public $default = array( 'host' => 'smtp.gmail.com', 'port' => 465, 'username' => 'my@gmail.com', 'password' => 'secret', 'transport' => 'smtp', 'tls' => true }
more details can find in cakeemail documentation.
Comments
Post a Comment