1

I have phpmailer and the href have different value. When I inspect element, the URL are correct but when I click the Activate code the redirect will be different. enter image description here

This is my code:

$message = "
    <h2>Thank you for Registering.</h2>
    <p>Your Account:</p>
    <p>Email: ".$email."</p>
    <p>Password: ".$_POST['password']."</p>
    <p>Please click the link below to activate your account.</p>
    <a href='".$_SERVER['HTTP_HOST']."/activate.php?code=".$code."&user=".$userid."'>Activate Account</a>";

$mail = new PHPMailer(true);                             
try {
    //Server settings
    $mail->isSMTP();                                     
    $mail->Host = 'smtp.mailtrap.io';                      
    $mail->SMTPAuth = true;                               
    $mail->Username = 'e0891ddb9b14a1';     
    $mail->Password = '373f8f6c93f27d';                                         
    $mail->Port = 465;                                   

    $mail->setFrom('jeraldpunxbot1@gmail.com');

    //Recipients
    $mail->addAddress($email);              
    $mail->addReplyTo('jeraldpunxbot1@gmail.com');

    //Content
    $mail->Subject = 'ShopNow Sign Up';
    $mail->Body    = $message;
    $mail->isHTML(true);                                  

    $mail->send();

    unset($_SESSION['firstname']);
    unset($_SESSION['lastname']);
    unset($_SESSION['email']);

    $_SESSION['success'] = 'Account created. Check your email to activate.';
    header('location: signup.php');
} catch (Exception $e) {
    $_SESSION['error'] = 'Message could not be sent. Mailer Error: '.$mail->ErrorInfo;
    header('location: signup.php');
}
Storm Spirit
  • 1,440
  • 4
  • 19
  • 42
  • The url you have given is being interpreted relative to your host. Try giving a complete URL with https://{your-url-goes-here}... – arjnt Jun 23 '19 at 05:51

1 Answers1

2

You forgot the https:// on the URL, so the browser interpreted it as a relative link.

  • relevant link supporting your answer: https://stackoverflow.com/questions/14768153/how-do-browsers-determine-whether-an-url-in-an-href-is-relative-or-not-when-usin –  Jun 23 '19 at 05:33