The code works to send the email with link included bu the URL does not open. Can anyone help?

//Send Email For Account Confirmation

$s_web="http://".$_SERVER[HTTP_HOST];
$message="Please activate your account by running this link:"."\n\n"; 
$message.=$s_web.'/confirmaccount.php?code='.$encryptpass.'&id='.$id."\n\n";


$headers = 'From:'.$s_mail."\n" .
    'Reply-To:'.$s_mail."\n" .
    'X-Mailer: PHP/' . phpversion();

mail ($emailaddress,'New Account Confirmation',$message,$headers);

}
mysql_close($connect);

link goes here:
/confirmaccount.php?code=25d55ad283aa400af464c76d713c07ad&id=735e6b81a8648674bda78409d471d536

Member Avatar for iamthwee

A clickable link has the following format:

<a href="http://www.daniweb.com">click me</a>

If you paste the url into your address bar in your browser and go directly to it, does it work?

If it works and you truly are just trying to make it a clickable link in the email, then

$message .= "<a href='$s_web/confirmaccount.php?code=$encryptpass&id=$id'>confirm account</a>";

Thanks but that did not work in the message. BTW the email link does confirm the registration when you go to that link. I would put a thank you message at that url but it really doesnot exist. Any ideas?

Member Avatar for iamthwee

Maybe you don't have html text enabled in your email client, in which case you're screwed.

Need to set all the appropriate headers for sending html email.

Without getting to overly complicated (because you could make this a lot more complex), this is how I would probably do this

$s_web = "http://".$_SERVER[HTTP_HOST];

$subject = "New Account Confirmation";

$message = "<html><body>";
$message .= "<h1>Account Confirmation</h1>";
$message .= "<p>Please activate your account by running this link:</p><br />";
$message .= "<a href='$s_web/confirmaccount.php?code=$encryptpass&id=$id'>confirm account</a>";
$message .= "</body></html>";

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'To: <' . $emailaddress.'>' . "\r\n";
$headers .= 'From:' . $s_mail . "\r\n";
$headers .= 'Reply-To:' . $s_mail . "\r\n";
$headers .= 'Subject:' . $subject . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();

mail($emailaddress, $subject, $message, $headers);

I usually dump my headers into an array, etc. But this way works too. I also like using an html template rather than dumping the html into my PHP.

red pill, the headers solved the link in the email but that is not this issue. thanks for that. where I have an issue is the link opens to a 404 error. I need it to redirect to the location, http://ebookcashin.com/point after confirmation.

PS I think I need to add this somewhere: header("location:index.php");

Yes, to redirect you could do that. Make sure to set it right with capital "L", and I would recommend using a full url.

header("Location: http://www.domain.com/file.php");

the question is where do I put it?

It's hard to say without seeing the rest of your code. However, why are you getting a 404 error for confirmaccount.php? If done correctly, I would think you should not be getting a 404 error.

red, that is the issue here is the link generated via email: would you check to see if it is not my machine?
ttp://ebookcashin.com/confirmaccount.php?code=25d55ad283aa400af464c76d713c07ad&id=629e1b9cd5d3bf65c23bca821aab9a15

I get a custom 404 error message as well. Double check the name and location of that file. It's also possible that the nginx config settings could play a part in this, just like htaccess on Apache.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.