marcs910 Posted April 9, 2007 Share Posted April 9, 2007 I'm working on this user registration. Everything works besides the emailing. Any clues? <?php # register.php // Send NOTHING to the Web browser prior to the header() line! // Check if the form has been submitted. if (isset($_POST['submitted'])) { require_once ('mysql_connect.php'); // Connect to the db. $errors = array(); // Initialize error array. // Check for a first name. if (empty($_POST['first_name'])) { $errors[] = 'You forgot to enter your first name.'; } else { $fn = escape_data($_POST['first_name']); } // Check for a last name. if (empty($_POST['last_name'])) { $errors[] = 'You forgot to enter your last name.'; } else { $ln = escape_data($_POST['last_name']); } // Check for an email address. if (empty($_POST['email'])) { $errors[] = 'You forgot to enter your email address.'; } else { $e = escape_data($_POST['email']); } // Check for a password and match against the confirmed password. if (!empty($_POST['password1'])) { if ($_POST['password1'] != $_POST['password2']) { $errors[] = 'Your password did not match the confirmed password.'; } else { $p = escape_data($_POST['password1']); } } else { $errors[] = 'You forgot to enter your password.'; } if (empty($errors)) { // Register the user in the database. // Check for previous registration. $query = "SELECT user_id FROM users WHERE email='$e'"; $result = mysql_query($query); if (mysql_num_rows($result) == 0) { //Create the activate code $a = md5(uniqid(rand(),true)); // Make the query. $query = "INSERT INTO users (first_name, last_name, email, password, company_name, description, address, city, state, zip, phone, fax, cell, web_address, active, registration_date) VALUES ('$fn', '$ln', '$e', SHA('$p'), '$cn', '$desc', '$add', '$city', '$st', '$z', '$ph', '$fax', '$cell', '$web', '$a', NOW() )"; $result = @mysql_query ($query); // Run the query. if (mysql_affected_rows() ==1) { // If it ran OK. // Send an email, if desired. $body = "Thank you for registering at the User Registration site. To activate your account, please follow this link:\n\n"; $body .= "http://www.my-domain.net/activate.php?x=" . mysql_insert_id() . "&y=$a"; mail($_POST['email'], 'Registration Confirmation', $body); // Redirect the user to the thanks.php page. // Start defining the URL. $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } // Redirect to. $url .= '/thanks.php'; header("Location: $url"); exit(); } else { // If it did not run OK. $errors[] = 'You could not be registered due to a system error. We apologize for any inconvenience.'; // Public message. $errors[] = mysql_error() . '<br /><br />Query: ' . $query; // Debugging message. } } else { // Email address is already taken. $errors[] = 'The email address has already been registered.'; } } // End of if (empty($errors)) IF. mysql_close(); // Close the database connection. } else { // Form has not been submitted. $errors = NULL; } // End of the main Submit conditional. // Begin the page now. $page_title = 'Register'; include ('header.html'); if (!empty($errors)) { // Print any error messages. echo '<h1 id="mainhead">Error!</h1> <p class="error">The following error(s) occurred:<br />'; foreach ($errors as $msg) { // Print each error. echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p>'; } // Create the form. ?> <h2>Register</h2> <form action="register.php" method="post"> <p>First Name: <input type="text" name="first_name" size="15" maxlength="15" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p> <p>Last Name: <input type="text" name="last_name" size="15" maxlength="30" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p> <p>Email Address: <input type="text" name="email" size="20" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /> </p> <p>Company Name: <input type="text" name="company_name" size="25" maxlength="25" /></p> <p>Description: <input type="text" name="desciption" size="25" maxlength="25" /></p> <p>Address: <input type="text" name="address" size="25" maxlength="25" /></p> <p>City: <input type="text" name="city" size="25" maxlength="25" /></p> <p>State: <input type="text" name="state" size="2" maxlength="2" /></p> <p>Zip: <input type="text" name="company_name" size="10" maxlength="10" /></p> <p>Phone: <input type="text" name="phone" size="25" maxlength="25" /></p> <p>Fax: <input type="text" name="fax" size="25" maxlength="25" /></p> <p>Cell: <input type="text" name="cell" size="25" maxlength="25" /></p> <p>Website: <input type="text" name="web_address" size="25" maxlength="25" /></p> <p>Password: <input type="password" name="password1" size="10" maxlength="20" /></p> <p>Confirm Password: <input type="password" name="password2" size="10" maxlength="20" /></p> <p><input type="submit" name="submit" value="Register" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php include ('footer.html'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/46214-solved-emailing/ Share on other sites More sharing options...
clown[NOR] Posted April 9, 2007 Share Posted April 9, 2007 maybe... just MAYBE mail($_POST['email'], "Registration Confirmation", $body); atleast they used the " on the mail() manual on php.net Quote Link to comment https://forums.phpfreaks.com/topic/46214-solved-emailing/#findComment-224707 Share on other sites More sharing options...
neel_basu Posted April 9, 2007 Share Posted April 9, 2007 Please clearify your problem. Is it firing any error ?? Quote Link to comment https://forums.phpfreaks.com/topic/46214-solved-emailing/#findComment-224750 Share on other sites More sharing options...
marcs910 Posted April 9, 2007 Author Share Posted April 9, 2007 No. There arent any errors. All required information from the form is placed in the table like it should and it redirects to the thanks.php. Quote Link to comment https://forums.phpfreaks.com/topic/46214-solved-emailing/#findComment-224896 Share on other sites More sharing options...
neel_basu Posted April 9, 2007 Share Posted April 9, 2007 No. There arent any errors. All required information from the form is placed in the table like it should and it redirects to the thanks.php. So whats the problem ?? Quote Link to comment https://forums.phpfreaks.com/topic/46214-solved-emailing/#findComment-224899 Share on other sites More sharing options...
clown[NOR] Posted April 9, 2007 Share Posted April 9, 2007 think his problem is that the email aint beeing sent u sure $_POST's still holding the value? just an idea mail($_POST['email'], 'Registration Confirmation', $body); Quote Link to comment https://forums.phpfreaks.com/topic/46214-solved-emailing/#findComment-224902 Share on other sites More sharing options...
marcs910 Posted April 9, 2007 Author Share Posted April 9, 2007 Yes. Thanks clown. The email is never being sent. I'm using my email in the form but I never recieve anything. Quote Link to comment https://forums.phpfreaks.com/topic/46214-solved-emailing/#findComment-224912 Share on other sites More sharing options...
neel_basu Posted April 9, 2007 Share Posted April 9, 2007 First Check your Junk mail folder. Turn Error Reporting E_ALL. and try this if(isset($_POST['email']) || strlen($_POST['email']) != 0) { $header = "From: [email protected] \r\n"; if(!mail($_POST['email'], 'Registration Confirmation', $body, $header)) { echo "Mail Sending Failed\n"; } else { echo "Mail Sent Successfully\n"; } } else { echo base64_encode("email not Set"); } e.g. Replace mail($_POST['email'], 'Registration Confirmation', $body); With this Codes Quote Link to comment https://forums.phpfreaks.com/topic/46214-solved-emailing/#findComment-224914 Share on other sites More sharing options...
marcs910 Posted April 9, 2007 Author Share Posted April 9, 2007 Heh. It was in my spam mail folder in gmail. Thanks. Now how can I keep it from being seen as spam? This is the way it came in H-Sphere Httpd Daemon <[email protected]> to me Quote Link to comment https://forums.phpfreaks.com/topic/46214-solved-emailing/#findComment-224918 Share on other sites More sharing options...
clown[NOR] Posted April 9, 2007 Share Posted April 9, 2007 from what i've been reading you have to do some changes in the header... you find all about it on php.net and google =) hehehe Quote Link to comment https://forums.phpfreaks.com/topic/46214-solved-emailing/#findComment-224921 Share on other sites More sharing options...
neel_basu Posted April 9, 2007 Share Posted April 9, 2007 Heh. It was in my spam mail folder in gmail. Thanks. Now how can I keep it from being seen as spam? This is the way it came in H-Sphere Httpd Daemon <[email protected]> to me The Easiest Way for doing this is Using the mail Class You will Find it over here http://zigmoyd.sourceforge.net/man/mail.php#mailDownload It And use it Properly. Quote Link to comment https://forums.phpfreaks.com/topic/46214-solved-emailing/#findComment-224926 Share on other sites More sharing options...
marcs910 Posted April 9, 2007 Author Share Posted April 9, 2007 I got this one working just like I needed it by adding a $header with a value. Thanks guys Quote Link to comment https://forums.phpfreaks.com/topic/46214-solved-emailing/#findComment-225121 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.