使用Zend_Mail发送带变量的链接

时间:2016-03-28 22:29:20

标签: php zend-framework hyperlink zend-mail email-confirmation

我很高兴在用户完成注册时发送带有链接的电子邮件。 该链接应具有带有用户ID的变量$ id。 我尝试了不同的东西,但我的链接总是显示为
?HTTP://localhost/users-data/activate/.php ID =>

我正在使用Zend_Mail。 我想要做的是,例如:发送给用户id = 1链接http://localhost/users-data/activate1。那时我可以获取最后一个url,它应该对应id,并在我的激活脚本中为这个用户设置状态。

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

这是我的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;
}

这是我的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);

    }

}

3 个答案:

答案 0 :(得分:0)

您从$_request转到if object_id('tempdb..#t1') is not null drop table #t1 create table #t1 (ID int, name varchar(10)) insert into #t1 values (1,'2'), (6,'2'), (6,'2'), (1,'4') DECLARE @CHARS VARCHAR(100) = '' SELECT @CHARS = @CHARS + name + ', ' -- <---CODE OF INTEREST FROM #t1 。后者未在任何地方定义,因此其值为空。

答案 1 :(得分:0)

试试这个

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

答案 2 :(得分:-1)

您创建的HTML链接不正确:

href

在HTML中,有效链接是(请注意<a href="http://...">...</a> 属性):

'<a href="http://localhost/users-data/activate/.php?id='.$id.'">'

所以你的脚本应该像这样构建链接:

http://localhost/users-data/activate/.php

另外,我认为php不是您想要的:您的脚本可能在gold = 0 def display(): calculate() calculate() def calculate(): global gold gold += 10 gold = gold + 10 print(gold) display() 扩展名之前有一个名称。