Php 使用Zend_邮件发送带有变量的链接

Php 使用Zend_邮件发送带有变量的链接,php,zend-framework,hyperlink,zend-mail,email-confirmation,Php,Zend Framework,Hyperlink,Zend Mail,Email Confirmation,当用户完成注册后,我将发送一封带有链接的电子邮件。 链接应该有一个带有用户id的变量$id。 我尝试了不同的方法,但我的链接总是显示为 http://localhost/users-data/activate/.php?id=> 我正在使用Zend_邮件。 我试图做的是,例如:向用户id=1发送一个链接。因此,我可以获取url的最后一个编号,它应该对应于id,并在激活脚本中为该用户设置状态 你能告诉我我做错了什么吗 这是我的注册操作 public function registerAction(

当用户完成注册后,我将发送一封带有链接的电子邮件。 链接应该有一个带有用户id的变量$id。 我尝试了不同的方法,但我的链接总是显示为 http://localhost/users-data/activate/.php?id=>

我正在使用Zend_邮件。 我试图做的是,例如:向用户id=1发送一个链接。因此,我可以获取url的最后一个编号,它应该对应于id,并在激活脚本中为该用户设置状态

你能告诉我我做错了什么吗

这是我的注册操作

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;
}
这是我的应用程序\u模型\u邮件

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);

    }

}

您可以从$request转到$u request。后者未在任何地方定义,因此其值为空。

您创建的HTML链接不正确:

'<a http://localhost/users-data/activate/.php?id='.$id.'>'
因此,您的脚本应该像这样构造链接:

'<a href="http://localhost/users-data/activate/.php?id='.$id.'">'
我想也是http://localhost/users-data/activate/.php 不是您想要的:您的脚本在php扩展之前可能有一个名称。

试试这个

$mail->setBodyHtml("Please click the following link to activate your".
"account<a href='http://localhost/users-data/activate.php?id=$id'>$id</a>")

谢谢你的回答!尽管如此,我的电子邮件显示如下:请单击以下链接激活您的帐户。因此,我可以获取url的最后一个编号,该编号应与id相对应,并在我的激活脚本中设置此用户的状态。谢谢您的回答。这样做链接就不会出现在电子邮件中…谢谢你的回复。但看起来,一旦$email和$name正确出现在电子邮件中,至少会设置它们。无论如何,我如何定义$\u请求?
$mail->setBodyHtml("Please click the following link to activate your".
"account<a href='http://localhost/users-data/activate.php?id=$id'>$id</a>")