确认码不会复制到phpmailer

时间:2014-04-25 20:08:18

标签: php phpmailer

好吧,我的问题是,当我尝试使用我已经创建的随机代码进行确认链接时,它不会传递给确认邮件。但是确认代码仍然可以毫无问题地插入到数据库中。这是我的代码:

 function NewUser()
    {
    $user = $_POST['user'];
    $pass = $_POST['pass'];
    $confirm = md5(uniqid(rand(), true));


    $success = "INSERT INTO members(user,pass,'$confirm')";
    $data = mysql_query ($success)or die(mysql_error());
    if($data)
    {if($data)
    {
     SendUserConfirmationEmail($confirm);   
    echo "<div class ='verdanacenter'><img src='img/bienvenido.png' title='Enhorabuena'/><br><br><br><font face ='verdana'>Welcome <b>$name $lname</b> !!!<br>Success.<br><br>Soon u will receive a confirmation msg to <b>$email</b>";
    }
    else
    {
        echo "<div class ='verdanacenter'><img src='img/alerta.png' title='Error'/><br><br><br><font face ='verdana'>Fatal Error !!!";
    }
}

    function SendUserConfirmationEmail($confirmcode)
    {   
    require 'PHPMailerAutoload.php';

    $mail = new PHPMailer();
    $mail->isSendmail();
    $mail->setFrom('info@rene.org', 'Rene');
    $mail->addAddress($_POST['email'],$_POST['name']);
    $mail->Subject = 'Welcome';
    $mail->IsHTML(true);    
    $confirmcode = $confirm;
    $mail->Body = '<p align="left"> Welcome <b>'.$_POST['name'].'</b>,</p><p align="justify">This is ur confirmation code:</p>
                                        <p align="left"><a href="http://www.rene.org/confirmar.php?code='.$confirmcode.'">CONFIRMAR</a>,</p>
                                        <p align="left">Regards,<br>
                                          Admin.<br>
                                          www.rene.org</p>';
    if (!$mail->send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        echo "Message sent!";
    }
        }

问题是,当我注册时,我会收到电子邮件,但没有随机代码($ confimcode)。看来:&#34; http://www.rene.org/confirmar.php?code=&#34;而不是&#34; http://www.rene.org/confirmar.php?code=A23B45423545V6764542543&#34;我想念的是什么人?请帮助。

1 个答案:

答案 0 :(得分:1)

这称为范围。

该函数无法从外部看到变量。要将该代码传递给函数,请将其包含在参数中:

function SendUserConfirmationEmail($confirmcode){
...

当你调用函数时,你传递变量:

SendUserConfirmationEmail($confirm);

在您的函数中的任何位置,该值将以$confirmcode

的形式提供

编辑:还注意到你在函数中有一个函数。不要这样做,只需将它们分开。