Jump to content

[SOLVED] emailing


marcs910

Recommended Posts

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');

?>

Link to comment
Share on other sites

First Check your Junk mail folder.

Turn Error Reporting E_ALL.

and try this

if(isset($_POST['email']) || strlen($_POST['email']) != 0)
{
	$header = "From: you@domain.com \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

Link to comment
Share on other sites

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 <httpd@mail.worldispnetwork.com>  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.

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.