Collegeboox Posted February 28, 2011 Share Posted February 28, 2011 I am having a problem with my php mail () function I have one page that works and one that doesn't the code is below if anyone can see the problem or can think of a problem please help me out thank you so much...... Code That Works... if ($submit) { if ($terms == 'disagree') { die ('If you do not agree to the Terms & Conditions than you are not permited to have an account on College Boox Store.'); } if ($terms == 'agree') { //open database $connect = mysql_connect("db","user","pass") or die("Not connected"); mysql_select_db("db") or die("could not log in"); $namecheck = mysql_query("SELECT username FROM TABLE*** WHERE username='$username'"); $count = mysql_num_rows($namecheck); if ($count!=0) { die("Username already taken please try again."); } function check_email_address($email) { // First, we check that there's one @ symbol, // and that the lengths are right. if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters // in one section or wrong number of @ symbols. die ("please enter a valid email address!"); } } // check for existance if($username&&$password&&$checkpassword&&$email&&$school) { // check if passwords match if ($password==$checkpassword) { // check username and email lentgh if (strlen($username)>25|| strlen($email)>35||strlen($school)>30) { echo "25/30 Character limit."; } else { // check password length if (strlen($password)>25||strlen($password)<6) { die ("Password must be between 6 and 25 characters."); } else { // register user echo ""; // open database $connect = mysql_connect("db","user","pass") or die("Not connected"); mysql_select_db("db") or die("could not log in"); // generate random numbers for activation $random = rand(23456789,98765432); $queryreg = mysql_query("INSERT INTO TABLE** Values ('','$firstname','$lastname','$username','$school','$password','$email','$date','$random','0')"); $lastid = mysql_insert_id (); //send activation email $to = "[email protected]"; $subject = "Activate Account"; $headers = "From:$email"; $server = "smtp.gmail.com"; ini_set("SMTP",$server); $body = "Register $firstname,\n\n Username = $username\n www.Collegebooxstore.com/activate.php?id=$lastid&code=$random\n\n"; //function to send email mail($to, $subject, $body, $headers); } } } else die ("Passwords do not match."); } else die ("Please fill in all fields."); } else die ('Please read the Terms & Conditions and make sure you check I agree if in order to create an account.'); } Code That Does Not Work... if ($submit) { //existance check if ($firstname&&$question) { //connect to database $connect = mysql_connect(db","user","pass") or die("Not connected"); mysql_select_db("user") or die("could not log in"); //grab email from database $query = "SELECT * FROM TABLE*** WHERE username='$username'"; $result = mysql_query($query); $row = mysql_fetch_array($result); //set email to variable name $email = $row['email']; //set SMTP $server = "smtp.gmail.com"; ini_set("SMTP",$server); //setup variables $to = "[email protected]"; $subject = "Activate Account"; $headers = "From:$email"; $server = "smtp.gmail.com"; ini_set("SMTP",$server); $body = "Register $firstname,\n\n Username = $username\n www.Collegebooxstore.com/activate.php?id=$lastid&code=$random\n\n"; //function to send email mail("[email protected]", $subject, $body, $headers); } else die('Please make sure your filled in your first Name as well as a Question/Comment!'); } Quote Link to comment https://forums.phpfreaks.com/topic/229139-php-mail-still-not-figured-out/ Share on other sites More sharing options...
kenrbnsn Posted February 28, 2011 Share Posted February 28, 2011 What do you mean by "doesn't work"? We're not mind readers. Also, please wrap your code in tags. Ken Quote Link to comment https://forums.phpfreaks.com/topic/229139-php-mail-still-not-figured-out/#findComment-1180775 Share on other sites More sharing options...
Collegeboox Posted February 28, 2011 Author Share Posted February 28, 2011 I usually do wrap it however I forgot...I mean that it never makes it to the desired mailbox Quote Link to comment https://forums.phpfreaks.com/topic/229139-php-mail-still-not-figured-out/#findComment-1180780 Share on other sites More sharing options...
Muddy_Funster Posted February 28, 2011 Share Posted February 28, 2011 Is there a reason you are assigning $to and then not using it? Quote Link to comment https://forums.phpfreaks.com/topic/229139-php-mail-still-not-figured-out/#findComment-1180783 Share on other sites More sharing options...
Collegeboox Posted February 28, 2011 Author Share Posted February 28, 2011 no I used to $to but it wasnt working so i decided to just put in the actual email address Quote Link to comment https://forums.phpfreaks.com/topic/229139-php-mail-still-not-figured-out/#findComment-1180784 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.