• PHP Help
  • Link Not Clickable in Verification Email

Working through a ‘register/login with verify’ script to make it work for my setup, and it does! Unfortunately, the email asking me to verify my form details doesn’t have a clickable link, just a url that I can copy/paste and get into the page. I get this in a Yahoo Mail account and a Hotmail account but not with gmail! Yahoo and Microsoft have somehow 'stripped' the ability from a link to be clicked.

Like I said, this works, even if it means copying and pasting the plain text into a browser to continue verification. But it would be great if I could have a link show up in all email clients.

Can someone inform me as to what to do to get the link in the email to appear in link form so I can maybe turn it into a button?!

<?php 
	require('PHPMailer/PHPMailerAutoload.php'); 
	require('crediantial.php');

?>
<!DOCTYPE html>
<html>
<head>
	<title></title>
	<!-- Latest compiled and minified CSS -->
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<link rel="stylesheet" href="css/aos.css" />

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<script>
  AOS.init();
</script>

</head>
<body>
<?php 
$conn = mysqli_connect("******","******","******","***");

if(isset($_POST['register'])){
	
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
$repassword = $_POST['repassword'];

$token = md5(rand('10000', '99999'));
if ($password !== $repassword) {
	$msg =  "Password & Retype password not match";
}else{
	$select = "INSERT INTO register(name,email,password,token,status)VALUES('".$name."','".$email."','".$password."','".$token."','Inactive')";
	$result = mysqli_query($conn,$select);

	$lastId = mysqli_insert_id($conn);
	
	// Set email format to HTML
	 
		$url = 'https://*******'.$_SERVER['SERVER_NAME'].'/property7/register/verify.php?id='.$lastId.'&token='.$token; 
		$url_components = parse_url($url); 
		parse_str($url_components['query'], $params); 
		 
	
   
	
	$output = '<div>Thanks for registering with localhost. Please click this link to complete this registation <br>'.$url.'</div>';

	if ($result == true) {

		$mail = new PHPMailer();
		//$mail->isSMTP();  
		//$mail->SMTPDebug = 2;                                   // Set mailer to use SMTP
		//$mail->Host = 'ssl://smtp.gmail.com:465';  					// Specify main and backup SMTP servers
		//$mail->IsHTML(true)
		$mail->Host = 'smtp.gmail.com';
		$mail->SMTPAuth = true;                               // Enable SMTP authentication
		$mail->Username = EMAIL;                 		// SMTP username
		$mail->Password = PASS;                           // SMTP password
		$mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
		$mail->Port = 587;
		                                    // TCP port to connect to

		$mail->setFrom(EMAIL, 'localhost tut');
		$mail->addAddress($email, $name);     // Add a recipient
		
		//$mail->addAddress('ellen@example.com');               // Name is optional
		//$mail->addReplyTo('info@example.com', 'Information');
		//$mail->addCC('cc@example.com');
		//$mail->addBCC('bcc@example.com');

		//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');         // Add attachments
		//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
		
		
		$mail->isHTML(true);

		$mail->Subject = 'Register confirmation';
		$mail->Body    = $output;
		//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

		if(!$mail->send()) {
			echo 'Message could not be sent.';
			echo 'Mailer Error: ' . $mail->ErrorInfo;
		} else {
			$msg = '<div class="alert alert-success">Congratulation, Your registration has been successful. please verify your account.</div>';
		}
	}
}
}

?>

<br><br><br><br>
<div class="container">
	<center>
		<h1>Registraion with email verify link using phpmailer</h1>
	</center>
	<hr>
	<center>
		<?php if (isset($msg)) { echo $msg; } ?>
	</center>
	<form action="" method="post">
		<div class="row" style="background:#e6ebe5">
			<div class="col-md-12" style="padding:20px;width:40%">
				<div class="form-group">
					<label>Enter Name</label>
					<input class="form-control" type="text" name="name" placeholder="Enter Name" required="">
				</div>
				
				<div class="form-group">
					<label>Enter Email</label>
					<input class="form-control" type="email" name="email" placeholder="Enter Email">
				</div>
				
				<div class="form-group">
					<label>Enter Password</label>
					<input class="form-control" type="password" name="password" placeholder="Enter Password">
				</div>

				<div class="form-group">
					<label>Enter Re Password</label>
					<input class="form-control" type="password" name="repassword" placeholder="Enter Re Password">
				</div>

				<div class="form-group">
					<input class="btn btn-success pull-left" type="submit" name="register" value="Register">
					<a href="login.php" class="btn btn-warning pull-right">Log In</a>
				</div>
			</div>
		</div>
		
	</form>
</div>

<div class="container">

	
</div>
			

					
				



</body>
</html>
<script src="js/aos.js"></script>
<script>
  AOS.init({
    easing: 'ease-in-out-sine'
  });
</script>

    Welcome to the forum. I replaced back-ticks (in-line code) with [code]...[/code] tags (code block) in the your post.

    I'll look more closely at your question later as time allows, if no one else has answered by then.

      I'm not seeing where you actually create a link within the email message? (Maybe it's just my old eyes?)

        Sorry for my messy code!

        Here's a link to the actual complete file:

        https://u.pcloud.link/publink/show?code=XZS1xvkZcjzYkeC2epm0skzf0IzRuY3wXjh7

        Line 51 is the one in question.

        $url = 'https://...'.$_SERVER['SERVER_NAME'].'/property7/register/verify.php?id='.$lastId.'&token='.$token;

        The above https link shows as a link if you give a gmail email address but not for hotmail or yahoo. PHPBuilder emailed me on my yahoo account and I was able to clike an actual link from within the email so I know it can be done!

        Thanks for your patience....

          Looks like you just want to turn it into an <a> element:

          $output = '<div>Thanks for registering with localhost. Please click this link to complete this registation <br><a href="'.$url.'">displayed link text here</a></div>';
          

          (substituting whatever you want to actually display in place of "displayed link text here". 😉 )

            PS: Or maybe better text-wise...

            $output = '<div>Thanks for registering with localhost. Please <a href="'.$url.'">click this link</a> to complete this registation</div>';
            

              Doesn't work, I'm afraid. Something to do with the 'token' that's generated during registration, it makes the url different from a regular 'webpage location' link.

              The whole page is rendered empty! Even if you right-click to view source - nothing.

              I don't know how debugging works but have been told to use 'die()' in the code to indicate where errors occur....

              You may be able to get some useful debug info by adding the following at the beginning of the file:

              <?php
              ini_set('display_errors', true); // change to false in production
              error_reporting(E_ALL);
              

              If you want to temporarily look at something at some point in the script:

              // something you do:
              $foo = some_function_or_whatever($bar);
              // see what happened:
              die("<pre>FOO:\n".var_export($foo, true)."</pre>");
              

                chome4 Doesn't work, I'm afraid. Something to do with the 'token' that's generated during registration, it makes the url different from a regular 'webpage location' link.

                Are you saying that the link becomes clickable if the token is left out (even if registration fails because of the missing token)?

                  Good question. I'm new to php. The token seems to be all-important as it's part of the registration process and is used to add the user to the database for authentication - I think.

                  The fact that the link IS clickable if you specify a gmail address in the form seems to point to the yahoo/hotmail side of things. Like I said, I'm new to this and this issue seems like and advanced one.

                  Here's a link to form so you can try it with any email to see the end result.

                  https://gmjones.org/property7/register/index.php

                  ps....the link leads to nowhere....for now!

                    Well I do see the email link and it looks like the IP address and domain name have both been stuffed into the hostname part of the URL instead of just the domain name.

                    The mail interface I've got doesn't do a source view and isn't rendering any HTML so I don't know if that's there, but it reads:

                    Subject: Register confirmation
                    Thanks for registering with localhost. Please click this link to complete this registation
                    https://[ip elided][domain name elided]/property7/register/verify.php?id=32&token=692f4a795f36e4289fd2626f6dca152c

                    As per the line $url = 'https://**.**.***.***'.$_SERVER['SERVER_NAME'].'/property7/register/verify.php?id='.$lastId.'&token='.$token; where I'm guessing the **** bit is an IP address.

                      OK, I see.

                      That's what comes of getting the original from a youtube video in order to learn stuff!

                      I'll see what I can do with the url later on....

                      I've cleared the dabase of emails. I'll update here later.

                      Thanks to you both for your help so far.

                        I've changed
                        $url = 'https://80.82.116.160'.$_SERVER['SERVER_NAME'].'/property7/register/verify.php?id='.$lastId.'&token='.$token;

                        to
                        $url = 'https://80.82.116.160/property7/register/verify.php?id='.$lastId.'&token='.$token;

                        Still with the same effect. At least I didn't get any php errors.

                        The 'verify.php' page was taken from here:

                        <?php
                        $conn = mysqli_connect("localhost","root","","registration");
                        //if(isset($_POST['login'])){
                        $id = $_GET['id'];
                        $token = $_GET['token'];
                        $select = "UPDATE register SET status = 'Active' WHERE id = '$id' AND token = '$token'";
                        $result = mysqli_query($conn,$select);
                        if ($result) {
                        echo "verify successful. you can log in now";
                        }else{
                        echo "verify faild";
                        }
                        //}
                        ?>

                        Worth mentioning that my gmail account is added to my mail.yahoo.com page and the link doesn't work if the gmail account is opened via yahoo mail but works when I go to the dedicated gmail web page.

                          a month later

                          When facing these sorts of issues, keep in mind that some MUAs (Mail Clients, and I'm glaring at YOU, Outlook) automatically parse URLs into clickable links. So confusion about why you have a clickable link in some MUA and not in some others is usually because you didn't create a clickable link, but your mail software did.

                            Write a Reply...