I am triyng to send a email with a link when the user complete registration. The link should have a variable $id with the id of the user. I tried different things but my link always appear as
http://localhost/users-data/activate/.php?id=>
I am using Zend_Mail. What I am trying to do, is for example: send to user id =1 a link http://localhost/users-data/activate1. For then I can take the last number of url, which should correspond to id, and set the status to this user in my activate script.
Could you show me what I doing wrong?
This is my registerAction
public function registerAction()
{
// action body
$request = $this->getRequest();
$form = new Application_Form_UsersData();
if ($this->getRequest()->isPost()) {
if ($form->isValid($request->getPost())) {
$comment = new Application_Model_UsersData($form->getValues());
$mapper = new Application_Model_UsersDataMapper();
$mapper->save($comment);
// send email
$id = $comment -> getId();
$formValues = $this->_request->getParams();
$mail = new Application_Model_Mail();
$mail->sendActivationEmail($formValues['email'], $id,$formValues['name']);
$this->_redirect('/users-data/regsuccess');
}
}
$this->view->form = $form;
}
This is my Application_Model_Mail
class Application_Model_Mail
{
public function sendActivationEmail($email, $id,$name)
{
require_once('Zend/Mail/Transport/Smtp.php');
require_once 'Zend/Mail.php';
$config = array('auth' => 'login',
'username' => '*******@gmail.com',
'password' => '******',
'port' => '587',
'ssl' => 'tls');
$tr = new Zend_Mail_Transport_Smtp('smtp.gmail.com',$config);
Zend_Mail::setDefaultTransport($tr);
$mail = new Zend_Mail();
$mail->setBodyText('Please click the following link to activate your account '
. '<a http://localhost/users-data/activate/.php?id='.$id.'>'.$id.'</a>')
->setFrom('admin@yourwebsite.com', 'Website Name Admin')
->addTo($email, $name)
->setSubject('Registration Success at Website Name')
->send($tr);
}
}
You go from $request
to $_request
. The latter is not defined anywhere, so its values are null.
The HTML link you create is incorrect:
'<a http://localhost/users-data/activate/.php?id='.$id.'>'
In HTML, a valid link is (note the href
attribute):
<a href="http://...">...</a>
So your script should construct the link like this:
'<a href="http://localhost/users-data/activate/.php?id='.$id.'">'
Also, I suppose http://localhost/users-data/activate/.php
is not what you want: your script has probably a name before the php
extension.
Try this
$mail->setBodyHtml("Please click the following link to activate your".
"account<a href='http://localhost/users-data/activate.php?id=$id'>$id</a>")