Jump to content

Send activation


Ashoar

Recommended Posts

I just realized an error in my coding where upon registering an account you get sent an activation key by email to activate your account.

This all works well except in the script to send it i am using this:

\n".$name."/activate.php?id=".$act."\n

 

$name is a variable made earlier in the code that contains the main url for the forum e.g http://www.myforum.com/forum

Except in the email it does not show up, it is just a blank space.

 

Is it possible to fetch the main url of the website the registration script is on and insert it directly into the email code?

Link to comment
Share on other sites

Here is the code, and after wars are just error messages:

 

<?php
session_start(); 
include 'config.php';
if(isset($_POST['submit']))
{

$first = addslashes(trim($_POST['firstname']));
$username = addslashes(trim($_POST['username']));
$email = addslashes(trim($_POST['email']));
$pass = addslashes(trim($_POST['password']));
$conf = addslashes(trim($_POST['confirm']));

$ip = $_SERVER['REMOTE_ADDR'];
$date = date("d, m y");

if ( $_POST['password'] == $_POST['confirm'] )
{}else{

	echo '<script>alert("Your passwords did not match. Please re-enter your password exactly the same in both sections.");</script>';
	echo '<script>history.back(1);</script>';
	exit;

}

$password = md5($pass);

if ((((( empty($first) ) || ( empty($username) ) || ( empty($email) ) || ( empty($password) )))))
{

	echo '<script>alert("You did not complete all fields. Please go back and fill in all fields.");</script>';
	echo '<script>history.back(1);</script>';
	exit;

}

if((!strstr($email , "@")) || (!strstr($email , ".")))
{

	echo '<script>alert("The email address you entered is not valid. Please enter a different email.");</script>';
	echo '<script>history.back(1);</script>';
	exit;

}

$q = mysql_query("SELECT * FROM Users WHERE Username = '$username'") or die(mysql_error());
if(mysql_num_rows($q) > 0)
{

	echo '<script>alert("The username you entered is already in use by another member. Please choose a different username.");</script>';
	echo '<script>history.back(1);</script>';
	exit;

}

$actkey = mt_rand(1, 500).'f78dj899dd';
$act = sha1($actkey);

$query = mysql_query("INSERT INTO Users (Username, Password, Name, Email, Date, IP, Actkey) VALUES ('$username','$password','$first','$email','$date','$ip','$act')") or die(mysql_error());
$send = mail($email , "Registration Confirmation" , "Thank you for registering an account at ".$websitename.".\n\nYour username and password is below, along with details on how to activate your account.\n\nUser: ".$username."\nPass: ".$pass."\n\nClick the link below to activate your account:\n".$name."/activate.php?id=".$act."\n\nIf you did not register an account and this email was sent incorrectly please disregard it. \n\nPlease do not reply, this is an automated mailer.\n\nThanks", "FROM: auto@mailer.com");

 

The web address is stored in a variable in the config.php

 

Also another error to know about, this does not send to hotmail account, seems to only work with gmail.

Link to comment
Share on other sites

I do think you should figure out what is happening to your variable.  However, in answer to your question,  there are a couple of $_SERVER superglobs you might want to look at, like:

 

$_SERVER["SCRIPT_URI"]

 

or

 

$_SERVER["HTTP_HOST"].

 

 

 

 

 

Link to comment
Share on other sites

Whether or not your mail will be received is related to your MTA configuration.  With the proliferation of spam there are a lot of things you need to do to have your email accepted, not the least of which is having a valid MX record for the server, having a valid reverse dns entry for the mail server, and having an SPF entry.  Chances are your hotmail email is either being outright rejected or is being spam filtered within hotmail.  Check the mail logs of the server, and the spam folder of the hotmail account you are using for testing.

Link to comment
Share on other sites

<?php

$l = mysql_connect ( "**********" , "************" , "**********" ) or die("Error connecting: <br><br>".mysql_error());
mysql_select_db( "********" ) or die("Error getting db: <br><br>".mysql_error());

$Name = "http://www.forum.mywebsite.com";

$websitename = "Jforum";

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.