View Full Version : php email confirmation...
lirhahs
09-14-2007, 03:26 PM
hello...
i have a problem with this..
can anyone tell me step by step how to email confirmation..like this forum..after i register, the confirmation email has been sent to my email address..and after that, they ask me to click the link so that my account will activated..please help me........
jc_gmk
09-14-2007, 03:45 PM
You can use the mail() function to send confirmation emails.
All you need to do is set up a form and post the values to this php script
e.g.
//These are the variables for the email
$sendto = $_POST['email']; // this is the email address collected form the form
$ccto = "you@yourdomain.com"; //you can cc it to yourself
$subject = "email confirmation"; // Subject
$message = "the body of the email - this email is to confirm etc..."
$header = "From: auto-confirm@yourdomain.com\r\n";
$header .= "Reply-to: you@yourdomain.com\r\n";
// This is the function to send the email
mail($sendto, $subject, $message, $header);
This is only the basics, there's alot more to include in the script, like checking whether or not they've entered a valid email address etc. but this should give you a starting point.
boogyman
09-14-2007, 03:56 PM
part 2 of your question is more difficult.
1) create an activated field in database (default to inactive)
2) upon registration, the email is sent
3) populate a link in the email, to include...
a) user unique identifier
b) activation to active
so it would look something like this potentially
[code]
Welcome __username___. Thanks for registering, please click on the link below to activate your account
domain.com/register.php?uid=100&activate=1
4) is your registration script attempt to grab the user by the id
5) update the activated field to true
and there u have a new and active user.
djr33
09-14-2007, 08:08 PM
you'll want to generate a unique activation code for each user. You can use microtime() to get a random number, then run that through some hash algorithm, like md5().
That will be an easy way to be sure they can't just figure out their confirmation.
I'm sure you implied that, but good to be extra clear on that.
I set up a similar system a bit ago. It wasn't that difficult, compared to other operations with php.
I added a nice interface, though, by having a link that would automatically activate the account, and a backup.
If they simply tried to log in, it would lock them out with a screen asking for the activation. They could then manually enter the code.
It was easy, then, however they proceed from the registration phase.
Additionally, I included a "cancel account" option on that validation page, if they decided they didn't want an account after all, so it was less work for the admin.
Also, having a "resend validation email" is a good idea. The 'cancel account' option could be used for that, and it could also help if they didn't get the email because they supplied the wrong email address.
mscreativedesigns
01-07-2010, 04:07 PM
Hey i saw this post online and its basically what im looking for but i was wondering if someone could help me with my php code.
what i want it to do is take my form data and send the data to my email address send the person a confirmation email and redirect them to my homepage.
here is the code i have now..
right now i have it to where it will send the data to my email say thank you for submitting the form and redirects them to my home page using java script at the bottom.. can some one help me out.. thanks..
<?php
if(isset($_POST['submit'])) {
$to = "mscreativedesigns@gmail.com";
$subject = "Design Service Inquiry";
$name_field = $_POST['name'];
$company_field = $_POST['company'];
$phone_field = $_POST['phone'];
$date_field = $_POST['date'];
$email_field = $_POST['email'];
$message_field = $_POST['message'];
$body = "From: $name_field
Company: $company_field
E-Mail: $email_field
Phone Number: $phone_field
Date: $date_field
Message: $message_field";
echo "We've recived your contact information $to! We will be in Contact with you shortly!" ;
mail($to, $subject, $body);
//These are the variables for the email
$sendto = $_POST['email']; // this is the email address collected form the form
$ccto = "matt@mscreativedesigns.com"; //you can cc it to yourself
$subject = "email confirmation"; // Subject
$message = "the body of the email - this email is to confirm etc..."
$header = "From: auto-confirm@mscreativedesigns.com\r\n";
// This is the function to send the email
mail($sendto, $subject, $message, $header);
} else {
echo "An error has occured, please email mscreativedesigns@gmail.com with your ";
}
?>
<script language=javascript>
setTimeout("location.href='index.html'", [3000]);
</script>
djr33
01-07-2010, 05:20 PM
What exactly is NOT happening then? Email is sent to you, confirmation is displayed on the page, and the redirect works? Are they not getting the confirmation email?
If $_POST['email'] is correctly set, I think that email would work.
Note that $ccto is not actually being used anywhere, so that will not work. If you want it to, you can do this (after the line defining $ccto):
$sendto = $sendto.', '.$ccto; //add the emails together
There are some possibly better ways to approach a few of these things (for example, a non-javascript redirect), but in general it should be working.
kairick
06-08-2010, 12:37 PM
Hi
I used SiteGrinder 2 Pro to set up this small website with a PHP registration form. SiteGrinder essentially set up the fields and all, but I had to hand code to do something more complex. On submit, the client wants the form to send the information to their (client's) email, and send an email ("thank you for registering, you entered the following information...") to the sender as well, AND be re-directed to another page on the site. I'm getting a parsing error, which makes sense because I know next to squat about php.
<?php
if(($_POST['college']=="")||($_POST['streetaddress']=="")||($_POST['city']=="")||($_POST['zip']=="")||($_POST['state']=="")||($_POST['contactperson']=="")||($_POST['contactemail']=="")||($_POST['phone']=="")||($_POST['fax']==""))
{
echo "<html><body><p>The following fields are <strong>required</strong>.</p><ul>";
if($_POST['college'] == ""){ echo "<li>*College</li>"; }
if($_POST['streetaddress'] == ""){ echo "<li>*Street Address</li>"; }
if($_POST['city'] == ""){ echo "<li>*City</li>"; }
if($_POST['zip'] == ""){ echo "<li>*Zip</li>"; }
if($_POST['state'] == ""){ echo "<li>*State</li>"; }
if($_POST['contactperson'] == ""){ echo "<li>*Contact Person</li>"; }
if($_POST['contactemail'] == ""){ echo "<li>*Contact Email</li>"; }
if($_POST['phone'] == ""){ echo "<li>*Phone</li>"; }
echo "</ul><p>Please use your browsers <a href=\"javascript:history.back();\">Back</a> button and fill out these fields.</p></body></html>";
}
if(isset($_POST['submit'])) {
$to = "my@email.com";
$subject = "Contact Has Registered";
$college = $_POST['college'];
$streetaddress = $_POST['streetaddress'];
$city = $_POST['city'];
$state = $_POST['date'];
$contactperson = $_POST['contactperson'];
$contactemail = $_POST['contactemail'];
$phone = $_POST['phone'];
$body = "From: $college
Street Address: $streetaddress
E-Mail: $contactemail
Phone Number: $phone
Contact Email: $contactemail
Message: $message_field";
mail($to, $subject, $body);
//These are the variables for the email
$sendto = $_POST['contactemail']; // this is the email address collected form the form
$ccto = "my@email.com"; //you can cc it to yourself
$subject = "Registration"; // Subject
$message = "Thank you for registering with..."
$header = "From: my@email.com\r\n";
location.href='attendee.html';
// This is the function to send the email
mail($sendto, $subject, $message, $header);
}
?>
<script language=javascript>
setTimeout("location.href='index.html'", [3000]);
</script>
The error states:
Parse error: syntax error, unexpected T_VARIABLE in /home_contact.php on line 50
Line 50 refers to the "$header = "From: my@email.com\r\n";" line.
Thanks for any assistance and try not to laugh too hard at my screw ups. :)
bluewalrus
06-08-2010, 01:07 PM
Line 45 needs a semicolon
$message = "Thank you for registering with..."
should be
$message = "Thank you for registering with...";
kairick
06-08-2010, 07:48 PM
Now I'm getting a parsing error on line 52:
Parse error: syntax error, unexpected '=' in /home_contact.php on line 52
Line 52 is the
location.href='attendee.html'; line
Thanks!
bluewalrus
06-08-2010, 08:44 PM
Can you post the code you have the line you've stated isn't in the php you've posted above so that wouldn't be the error.
kairick
06-08-2010, 08:48 PM
Sorry about that Blue. Here is the code:
<?php
if(($_POST['college']=="")||($_POST['streetaddress']=="")||($_POST['city']=="")||($_POST['zip']=="")||($_POST['state']=="")||($_POST['contactperson']=="")||($_POST['contactemail']=="")||($_POST['phone']=="")||($_POST['fax']==""))
{
echo "<html><body><p>The following fields are <strong>required</strong>.</p><ul>";
if($_POST['college'] == ""){ echo "<li>*College</li>"; }
if($_POST['streetaddress'] == ""){ echo "<li>*Street Address</li>"; }
if($_POST['city'] == ""){ echo "<li>*City</li>"; }
if($_POST['zip'] == ""){ echo "<li>*Zip</li>"; }
if($_POST['state'] == ""){ echo "<li>*State</li>"; }
if($_POST['contactperson'] == ""){ echo "<li>*Contact Person</li>"; }
if($_POST['contactemail'] == ""){ echo "<li>*Contact Email</li>"; }
if($_POST['phone'] == ""){ echo "<li>*Phone</li>"; }
echo "</ul><p>Please use your browsers <a href=\"javascript:history.back();\">Back</a> button and fill out these fields.</p></body></html>";
}
if(isset($_POST['submit'])) {
$to = "my@email.com";
$subject = "Contact Has Registered";
$college = $_POST['college'];
$streetaddress = $_POST['streetaddress'];
$city = $_POST['city'];
$state = $_POST['date'];
$contactperson = $_POST['contactperson'];
$contactemail = $_POST['contactemail'];
$phone = $_POST['phone'];
$body = "From: $college
Street Address: $streetaddress
E-Mail: $contactemail
Phone Number: $phone
Contact Email: $contactemail
Message: $message_field";
echo "We've recived your contact information $to! We will be in Contact with you shortly!" ;
mail($to, $subject, $body);
//These are the variables for the email
$sendto = $_POST['contactemail']; // this is the email address collected form the form
$ccto = "my@email.com"; //you can cc it to yourself
$subject = "Registration"; // Subject
$message = "Thank you for registering with...";
$header = "From: my@email.com\r\n";
Location.href="attendee.html";
// This is the function to send the email
mail($sendto, $subject, $message, $header);
}
?>
<script type=text/javascript>
setTimeout("location.href='index.html'", [3000]);
</script>
fileserverdirect
06-08-2010, 09:24 PM
Umm....
location.href='attendee.html';
That would be javascript.
Try this:
header("location: attendee.html");
EDIT: Put that after you use mail(); and You may want to use conditonals on the mail like: if(mail(...))header("location: attendee.html"); else echo "Error, please try again";
kairick
06-09-2010, 01:15 PM
Thanks so much for your help.
The email is generating fine, but I would like to be able to include the information the user enters into the form in the email for their records. How would I do that?
<?php
if(($_POST['college']=="")||($_POST['streetaddress']=="")||($_POST['city']=="")||($_POST['zip']=="")||($_POST['state']=="")||($_POST['contactperson']=="")||($_POST['contactemail']=="")||($_POST['phone']=="")||($_POST['fax']==""))
{
echo "<html><body><p>The following fields are <strong>required</strong>.</p><ul>";
if($_POST['college'] == ""){ echo "<li>*College</li>"; }
if($_POST['streetaddress'] == ""){ echo "<li>*Street Address</li>"; }
if($_POST['city'] == ""){ echo "<li>*City</li>"; }
if($_POST['zip'] == ""){ echo "<li>*Zip</li>"; }
if($_POST['state'] == ""){ echo "<li>*State</li>"; }
if($_POST['contactperson'] == ""){ echo "<li>*Contact Person</li>"; }
if($_POST['contactemail'] == ""){ echo "<li>*Contact Email</li>"; }
if($_POST['phone'] == ""){ echo "<li>*Phone</li>"; }
echo "</ul><p>Please use your browsers <a href=\"javascript:history.back();\">Back</a> button and fill out these fields.</p></body></html>";
}
if(isset($_POST['submit'])) {
$to = "my@email.com";
$subject = "Contact Has Registered";
$college = $_POST['college'];
$streetaddress = $_POST['streetaddress'];
$city = $_POST['city'];
$state = $_POST['date'];
$contactperson = $_POST['contactperson'];
$contactemail = $_POST['contactemail'];
$phone = $_POST['phone'];
$body = "From: $college
Street Address: $streetaddress
E-Mail: $contactemail
Phone Number: $phone
Contact Email: $contactemail
Message: $message_field";
echo "We've recived your contact information $to! We will be in Contact with you shortly!" ;
mail($to, $subject, $body);
//These are the variables for the email
$sendto = $_POST['contactemail']; // this is the email address collected form the form
$ccto = "my@email.com"; //you can cc it to yourself
$subject = "Registration"; // Subject
$message = "Thank you for registering with...";
$header = "From: my@email.com\r\n";
// This is the function to send the email
if(mail($sendto, $subject, $message, $header)) header("location: attendee.html");
}
?>
<script type=text/javascript>
setTimeout("location.href='index.html'", [3000]);
</script>
fileserverdirect
06-10-2010, 01:44 AM
I've noticed that your script is very messy, some variables are being set and not used, $ccto and your using $_POST['contactemail'];
when its already set to $contactemail
To send the user their entered info, just paste this in (red):
if(mail($sendto, $subject, $body, $header)) header("location: attendee.html");
}
You may also want to add an else statement to EACH of the mail(); functions. If you need help, just ask.
djr33
06-10-2010, 04:13 AM
fsd, I don't believe [color] tags work within [php] blocks. I tried to fix your post (edited it) but it didn't change.
infocusweb
06-10-2010, 09:27 AM
hello
thank you for sharing code and i get good information for your side.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.