Ashoar Posted April 14, 2009 Share Posted April 14, 2009 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? Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 what is the rest of your e-mail code? one line doesn't help much lol Quote Link to comment Share on other sites More sharing options...
Ashoar Posted April 14, 2009 Author Share Posted April 14, 2009 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. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 $name isn't set anywhere in that script. Can you show us config.php? and why is there so many parenthesis on this line... <?php if ((((( empty($first) ) || ( empty($username) ) || ( empty($email) ) || ( empty($password) ))))) ? Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 14, 2009 Share Posted April 14, 2009 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"]. Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 14, 2009 Share Posted April 14, 2009 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. Quote Link to comment Share on other sites More sharing options...
Ashoar Posted April 14, 2009 Author Share Posted April 14, 2009 The config.php just has the connection info for the db and the normal variable for the forum url. I added in the global command but it doesn't show up in the email either. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 why not just set the $name var right before mail(); is called? Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 14, 2009 Share Posted April 14, 2009 No surprise that doesn't work -- no place in the script is there a definition for the variable $websitename. Hence it's empty. Quote Link to comment Share on other sites More sharing options...
Ashoar Posted April 14, 2009 Author Share Posted April 14, 2009 But config.php is included meaning it would get that variable right from the config. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 show us config.php lol, and star **** your username, password, database lol Quote Link to comment Share on other sites More sharing options...
Ashoar Posted April 14, 2009 Author Share Posted April 14, 2009 <?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"; ?> Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 $Name has a capital N in config.php and when you call it in mail(); it is $name lower case n. Quote Link to comment Share on other sites More sharing options...
Ashoar Posted April 14, 2009 Author Share Posted April 14, 2009 So i do, i will fix that up, thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.