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('[email protected]');

    //Recipients
    $mail->addAddress($email);              
    $mail->addReplyTo('[email protected]');

    //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');
}
1
  • The url you have given is being interpreted relative to your host. Try giving a complete URL with https://{your-url-goes-here}... Commented Jun 23, 2019 at 5:51

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

relevant link supporting your answer: stackoverflow.com/questions/14768153/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.