preview

How to Code a Signup Form with Email Confirmation

Tutorial Details
  • Topic: PHP and mySQL
  • Difficulty: Beginner
  • Estimated Completion Time: 45 minutes

Final Product What You'll Be Creating

In this tutorial, we are going to be creating a user signup form that adds a user to a database, and then sends out a confirmation email that the user must click on before their account will be activated.


Step 1: The Template

I’ve included the basic site layout so we aren’t wasting time creating the form and making the site looks pretty. We are going to get right into coding which is what you came here for.

Open up the Site Template folder and copy it to either your localhost or web server.

Open up index.php and take a quick look. You’ll see a simple form with 3 inputs. These are the fields we are going to capture. We want the username, their password as well as their email. You can choose to capture other elements when users are signing up, but these are the 3 barebones elements we need.

preview

Step 2: Setting up the MySQL Database

Open up PHPMyAdmin or whatever program you use to manage your MySQL database and create a new database. You can name this whatever you like. Now we want to create the rows that are going to hold our user information and confirmation information. For this we create two tables. Users and Confirm.

CREATE TABLE `users` (
  `id` int(11) NOT NULL auto_increment,
  `username` varchar(50) NOT NULL default '',
  `password` varchar(128) NOT NULL default '',
  `email` varchar(250) NOT NULL default '',
  `active` binary(1) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=27 DEFAULT CHARSET=utf8;

Our first table has 5 rows. The first is the ID that is given to the user when they signup. This is set to auto increment so that each user is given a unique ID. Next is the username, password and ID. The last row lets us set the users active state. When we first create the user row, the active state will default to 0. This means that the users account is currently inactive. Once the user confirms their account we will set this to 1. This will state that the account is active.

CREATE TABLE `confirm` (
  `id` int(11) NOT NULL auto_increment,
  `userid` varchar(128) NOT NULL default '',
  `key` varchar(128) NOT NULL default '',
  `email` varchar(250) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=27 DEFAULT CHARSET=utf8;

Our second table is the confirm table. This holds the user’s ID and email as well as a randomly generated key that we will use to confirm the users account.


Step 3: Connecting to the MySQL Database

Open up inc/php/config.php.

First we need to make the connect to the database.

mysql_connect('localhost', 'username', 'password') or die("I couldn't connect to your database, please make sure your info is correct!");

Depending on your setup, we are going to need to change a few variables. So go ahead and fill in everything.

Next we need to tell MySQL which database we want to use.

mysql_select_db('your_database_name') or die("I couldn't find the database table make sure it's spelt right!");

Once everything has been edited to fit your database go ahead and point to the index.php file on your server.

If you don’t see any errors at the top, we are all connected.


Step 4: Submitting the Form

Ok, now that we are all connected to the database, we need to capture the form data so we can get the user signed up.

I’m going to give you the piece of code and then explain what’s going on. After that we are going to make changes and add functionality.

Here is the base; place this right after the first includes at the top of index.php

//check if the form has been submitted
if(isset($_POST['signup'])){

}

This if statement is checking to see if the form has been submitted.

Without this, our script would run every time the page is refreshed and we don’t want that.

Note: Depending on your application or just general style of coding this code may be placed in a separate file that is accessed when the form is submitted. I’ve placed the code all in one file to keep things simple and easy to follow along.


Step 5: Cleaning up and Checking the Variables

We want to make sure that the user has submitted actual content instead of just a blank form, so we are going to perform some quick checks.

The first part is to place the $_POST variables into simpler variables and clean them for the database. Place this inside our if statement.

$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$email = mysql_real_escape_string($_POST['email']);

mysql_real_escapse_string() makes sure that the user isn’t trying to use apostrophes to access our database with MySQL injection. Whenever you want to put information into a database the the user has inputed, please run it through mysql_real_escape_string(). For more information on MySQL injection you can read this article on Wikipedia

So, we’ve cleaned up our variables, now let’s check to see if the user forgot any fields.

if(empty($username)){ //put code in me please }
if(empty($password)){ //put code in me please }
if(empty($email)){ //put code in me please }

Now we have three if statements that are checking if each field is empty. If the field is empty we are going to assign some variables.

To make things clean we are going to create an array that will hold the status of the signup process as well as any text we need to show the user.

Right above that piece of code, let’s create an array and a few variables.

$action = array();
$action['result'] = null;

$text = array();

First we are creating a blank array called action and then setting an array value of result. Result is going to hold a value of either success or error. Next we create another blank array called text. This is going to hold any text we want to show the user during the signup.

Right now, our if statements that are checking our variables aren’t executing any code, so let’s go ahead and put some code inside the first if statement.

Put this code inside the username if statement.

$action['result'] = 'error';
array_push($text,'You forgot your username');

Let’s say the user submits the form without a username. Our statement is going to run the code above. First it’s going to set the result field of our action array to error.

Then we are going to use array_push() to put some text into our text array. We are going to be using this same piece of code for the final two “if” statements so copy and paste that code into the last two if statements. You’ll probably want to change the text to match the current if statement.

Note: We are using array_push() in case we have multiple errors in the form submission. If all if statements are executed, the text array will looks like:

Array(
	[0] => 'You forgot your username',
	[1] => 'You forgot your password',
	[2] => 'You forgot your email'
)

We now need to check if we have any errors so we can continue on with the signup process.


Step 6: No Errors, Let’s Signup the User

We are going to check to see if our action array result value is set to error.

if($action['result'] != 'error'){
	//no errors, continue signup
       $password = md5($password);
}
	
$action['text'] = $text;

We are also running our password through the md5() function. This takes the password and returns a 32 character string that looks something like this: a3470ce826283eca7ce3360d0f26b230. It’s good practice to run the password through some sort of hashing function before putting it into the database. This prevents people from viewing the users passwords if your database is hacked.

A quick check of our action result value and we can continue on with the signup. If our result is error we will skip over all this code and output the errors to our user so they can make the necessary changes.

The last piece of this code we are putting the values of your text array into our action array.


Step 7: Adding the User to the Database

Place this code inside our last if statement.

...
If Statement checking for errors
...

//add to the database
$add = mysql_query("INSERT INTO `users` VALUES(NULL,'$username','$password','$email',0)");
		
if($add){

	//the user was added to the database	
			
}else{
		
	$action['result'] = 'error';
	array_push($text,'User could not be added to the database. Reason: ' . mysql_error());
	=
}

We use mysql_query() and INSERT to insert the users information into the database. Next, we create another if statement checking to see if the user was added to the database. We do this by checking if the $add variable is true or false.

If the user is added we can continue on with the signup; if not we are going to assign some familiar variables and stop the signup.

When working with MySQL queries, we use the mysql_error() function if their are errors because it helps with debugging what is wrong with your queries. It will output text errors when something is wrong. This is good!


Step 8: Confirmation is Needed

The user has submitted the form, everything checks out and they’re now living in the database. We want the user to be able to use their account, so let’s setup the confirmation.

...
if added check
...

//get the new user id
$userid = mysql_insert_id();
			
//create a random key
$key = $username . $email . date('mY');
$key = md5($key);
			
//add confirm row
$confirm = mysql_query("INSERT INTO `confirm` VALUES(NULL,'$userid','$key','$email')");	
			
if($confirm){
			
	//let's send the email

}else{
				
	$action['result'] = 'error';
	array_push($text,'Confirm row was not added to the database. Reason: ' . mysql_error());
				
}

To make things easy, let’s assign the new user id to a variable so we can use it later. We do this by using mysql_insert_id(). This will set $userid to whatever the new user’s ID is.

Next we create the random key for that specific user. We create a variable named key and fill it with a value of the username, email and date. The string will look like mattmatt@email.com012009. After that we use the md5() function to convert it to a random string that is unique to that user.

Using mysql_query() and INSERT again, we put the new user ID, the key and the users email into the database.

preview

Step 9: Setting up the Email Templates

We are going to take a break from the PHP coding and create two new files. For the sake of being quick and easy we are actually going to use two templates that I’ve included with this tutorial. The two files we’re going to be looking at are signup_template.html and signup_template.txt. Swift lets us assign an HTML as well as a TXT version of the email incase the users email client doesn’t support HTML emails.

Open up signup_template.html Note: You can read up on HTML in emails over at carsonified. We aren’t going to be editing this file, i’m just going to explain whats going on and then you can play around with it once the tutorial is complete. The most important part of this file is the tags that look like {USERNAME} and confirm.php?email={EMAIL}&key={KEY}. We are going to write a function that uses this template and replaces those tags with the variables from our form.


Step 10: The Template Function

Open up inc/php/functions.php and place this code inside.

function format_email($info, $format){

	//set the root
	$root = $_SERVER['DOCUMENT_ROOT'].'/dev/tutorials/email_signup';

	//grab the template content
	$template = file_get_contents($root.'/signup_template.'.$format);
			
	//replace all the tags
	$template = ereg_replace('{USERNAME}', $info['username'], $template);
	$template = ereg_replace('{EMAIL}', $info['email'], $template);
	$template = ereg_replace('{KEY}', $info['key'], $template);
	$template = ereg_replace('{SITEPATH}','http://site-path.com', $template);
		
	//return the html of the template
	return $template;

}

format_email() is taking two variables which will be used in index.php. The first is our form information array and the second is format. We have a format variable so we can re-use this array for both the HTML and TXT versions of the template.

First we set the root. This points to the folder that the templates are hosted.

Next we open up the contents of our template and assign it to a variable.

Now we are going to use ereg_replace() to replace our {USERNAME} tags in our template with the content from our form. It’s basically just a super simple template system.

Lastly we return the template variable which holds all the html.

Explanation: In a nutshell, format_email() opens up our template files, takes the HTML and assigns it to our variable. This is just a cleaner way then assigning all the HTML in the function itself.


Step 11: Sending the Email

We are going to write another function to deal with Swift and sending the emails.

function send_email($info){
		
	//format each email
	$body = format_email($info,'html');
	$body_plain_txt = format_email($info,'txt');

	//setup the mailer
	$transport = Swift_MailTransport::newInstance();
	$mailer = Swift_Mailer::newInstance($transport);
	$message = Swift_Message::newInstance();
	$message ->setSubject('Welcome to Site Name');
	$message ->setFrom(array('noreply@sitename.com' => 'Site Name'));
	$message ->setTo(array($info['email'] => $info['username']));
	
	$message ->setBody($body_plain_txt);
	$message ->addPart($body, 'text/html');
			
	$result = $mailer->send($message);
	
	return $result;
	
}

Just like format_email(), send_email() takes our info array as a variable. The first part of the function we assign two variables, $body and $body_plain_text. We are using format_email() to assign the HTML values of our template to each variable. Now comes the good part. We have setup the swift instance using Swift_MailTransport:newInstance() and then setup the mailer using Swift_Mailer::newInstance($transport);

We create a new instance of the Swift message and start to assign some variables to this instance. We set the subject, from email and to email address and then use setBody() to assign out text version of the email to the mailer instance. To add the HTML version we use addPart(). The send() function takes care of the sending of the email and then we return the result. Alright, we have our email create and send functions written, let’s go back to index.php and start to wrap up the main signup.


Step 12: Did we Send? Shall we Confirm?

Our last bit should’ve been the if statement checking if the confirm row was created.

Let’s send the email and check if everything went though alright.

...
if confirm
...

//include the swift class
include_once 'inc/php/swift/swift_required.php';
			
//put info into an array to send to the function
$info = array(
	'username' => $username,
	'email' => $email,
	'key' => $key
);
			
//send the email
if(send_email($info)){
								
	//email sent
	$action['result'] = 'success';
	array_push($text,'Thanks for signing up. Please check your email for confirmation!');
				
}else{
					
	$action['result'] = 'error';
	array_push($text,'Could not send confirm email');
				
}

Without the Swift class we can’t send out any emails, so in our first line, we are including the swift class. We need to send our information to both of our new functions, so we create a new array and assign our variables to it. I know I know, more if statements, but we need to check for errors to make it easier for the users. You always have to assume that users will make every possible mistake imaginable.

We wrap our send_email() function in another if statement as well as passing the $info array. If the email is sent we assign a value of success and thank the user for signing up. If there are errors we use the familiar variables. So now, we are almost done with the signup, just one last function needs to be created. Even though we are assigning all these error/success variables and text we haven’t displayed this information to the user.

preview

Move back to functions.php and paste this code.

//cleanup the errors
function show_errors($action){

	$error = false;

	if(!empty($action['result'])){
	
		$error = "
    "."\n"; if(is_array($action['text'])){ //loop out each error foreach($action['text'] as $text){ $error .= "
  • $text

  • "."\n"; } }else{ //single error $error .= "
  • $action

  • "; } $error .= "
"."\n"; } return $error; }

This may seem confusing but it’s really just making our success/errors looks nice.

First it checks to see if the array is empty so we aren’t executing the code when it isn’t needed.

Next it creates a ul tag and applies the result as a class. This will either be success or error and is aesthetic only.

We then check to see if the text variable is an array or simply a string. If it’s a string, we wrap it in an li. If it’s an array we loop through each array item and wrap it in an li.

Lastly, we close the ul and return the entire string.

If we move back to index.php and place this code right after including header.php we can wrap up this section.

...
header include
...


A quick little explanation. We are taking all the values of our action array and passing it to the show_errors() function. If there is any content it returns a nice unordered list.


Step 13: Confirming the User

We should have a good grip on how the script is functioning; so for this next script I’m going to give you the entire chunk of code and then go through it with you.

Open up confirm.php and paste this in-between the header include and your show_errors() function.

//setup some variables
$action = array();
$action['result'] = null;

//quick/simple validation
if(empty($_GET['email']) || empty($_GET['key'])){
	$action['result'] = 'error';
	$action['text'] = 'We are missing variables. Please double check your email.';			
}
		
if($action['result'] != 'error'){

	//cleanup the variables
	$email = mysql_real_escape_string($_GET['email']);
	$key = mysql_real_escape_string($_GET['key']);
	
	//check if the key is in the database
	$check_key = mysql_query("SELECT * FROM `confirm` WHERE `email` = '$email' AND `key` = '$key' LIMIT 1") or die(mysql_error());
	
	if(mysql_num_rows($check_key) != 0){
				
		//get the confirm info
		$confirm_info = mysql_fetch_assoc($check_key);
		
		//confirm the email and update the users database
		$update_users = mysql_query("UPDATE `users` SET `active` = 1 WHERE `id` = '$confirm_info[userid]' LIMIT 1") or die(mysql_error());
		//delete the confirm row
		$delete = mysql_query("DELETE FROM `confirm` WHERE `id` = '$confirm_info[id]' LIMIT 1") or die(mysql_error());
		
		if($update_users){
						
			$action['result'] = 'success';
			$action['text'] = 'User has been confirmed. Thank-You!';
		
		}else{

			$action['result'] = 'error';
			$action['text'] = 'The user could not be updated Reason: '.mysql_error();;
		
		}
	
	}else{
	
		$action['result'] = 'error';
		$action['text'] = 'The key and email is not in our database.';
	
	}

}

Most of this should look very familiar; so I’m going to skip ahead and check if the key is in the database section.

Again, we use mysql_query() to get any rows in the database where the email and key are equal to the keys provided by the users email.

We use mysql_num_rows() to check if the number of rows returned is greater than 0.

If the email and key are in the database we grab all the information from the database using mysql_fetch_assoc().

Now that the user has confirmed his account, we need to update the database and set the active row to 1.

We use mysql_query() again, but instead of INSERT we use UPDATE to update the active row to 1 where the user ID is the same as our current users ID.

To clean everything up we use mysql_query() and DELETE to remove the confirmation row from the database. This makes sure that the user can’t come back to this page and reconfirm. It also keeps the database nice and clean.


Conclusion

We’ve covered many different areas in this tutorial. We downloaded and included a 3rd party script to deal with sending the emails, implemented simple form validation as well as created a super simple template system to style our emails. If you’re new to MySQL we’ve touched on the three most common functions in MySQL so you should have no problem completing some more advanced tutorials.


Final Notes

  • I’ve used Swift Mailer as our email deployment script which can be downloaded here: http://swiftmailer.org/
  • I’ve also used button styles provided by Zurb. Be sure to check them out and give them some love. http://www.zurb.com/blog_uploads/0000/0485/buttons-02.html

Thanks for reading and be sure to visit me on Twitter if you have any questions!

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • Khaled

    Matt, thanks a lot! you really walked me through this.

    I just want to add a few comments:

    Naming a column ‘key’ (when we create the confirm table) results in errors upon using a select statement, it drove me crazy for a while until I realized it is a reserved word. I just renamed it to ‘tempkey’.

    Also i had to remove all the single quotes from the column names for it to work.

  • Xavier

    Thanks for this tutorial, Matt. You will never know how useful it has been for me.

  • nhuy

    where template folder? i cant see index.php

  • muad

    how it works on step 11 line number 13 .. you put an array as a key inside another array .. caused illegal offset type..

  • futureproof

    Warning
    ereg_replace:

    This function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.

    “It’s basically just a super simple template system.”

    now that we know all there is to know about this function… haha

  • http://www.thedesignfactor.com Daniel

    Hi, I’m wondering if someone can help me. I have recently used this tutorial to develop a more complex sign up form for a competition for a client. Basically, the way the validation has been done is different to many other validation methods I’ve used before and don’t understand how to implement it, for some additional requirements.

    This is an example of the validation code that I have altered, to suit my form requirements:

    //quick/simple validation
    if(empty($code)){ $action['result'] = ‘error’; array_push($text,’You forgot to enter your entry code’); }
    if(empty($name)){ $action['result'] = ‘error’; array_push($text,’You forgot to enter your name’); }
    if(empty($email)){ $action['result'] = ‘error’; array_push($text,’You forgot to enter your email address’); }

    This code only validates that there is content there. But, for example on the ‘entry code’ field, I would like to put a maximum character input there and restrict certain characters, as well as a standard ‘email’ validation, so that the form is sent through to the database correctly.

    If anyone knows how I can do this, with this sign-up form in particular, please assist me, as every other method I’ve tried to work with this form hasn’t worked and caused the form to error.

    Thank you in advance.

  • someone

    I’m find that this dose not work. or connect to the database.

  • mohamad

    why my emai not confirmation?????????

  • Keir Symonds

    I’ve gone through everything and its been great. but when i sign up, it goes through, i get the email confirmation although the email is empty.

    When i click on the Sign up Now button it goes through fine, i get the message saying thanks for signing up, but above that i get a message saying there is a problem with line 9 of functions.php which is

    $template = file_get_contents($root.’/signup_template.html’);

    what is the problem im getting?

    the whole error message i get is:

    Warning: file_get_contents(/home/disorder/public_html/dev/tutorials/email_signup/source_revised/signup_template.html) [function.file-get-contents]: failed to open stream: No such file or directory in /home/disorder/public_html/inc/php/functions.php on line 9

    Warning: file_get_contents(/home/disorder/public_html/dev/tutorials/email_signup/source_revised/signup_template.html) [function.file-get-contents]: failed to open stream: No such file or directory in /home/disorder/public_html/inc/php/functions.php on line 9

    If you could help me that would be great
    Thanks!

    • http://kohn.cl AK

      The problem is in the function.php file, line 6.
      you have to define the right location of your “signup_template.html” file

      $root = $_SERVER['DOCUMENT_ROOT'].’/dev/tutorials/email_signup/source_revised’;

      In my case I changed for:

      $root = $_SERVER['DOCUMENT_ROOT'].’/learningPHP/signupemailform3′;

    • wasim

      hi i have problem the same like > Keir Symonds.

      I’ve gone through everything and its been great. but when i sign up, it goes through, i get the email confirmation although the email is empty.

      When i click on the Sign up Now button it goes through fine, i get the message saying thanks for signing up, but above that i get a message saying there is a problem with line 9 of functions.php which is

      $template = file_get_contents($root.’/signup_template.html’);

      what is the problem im getting?

      the whole error message i get is:

      Warning: file_get_contents(/home/disorder/public_html/dev/tutorials/email_signup/source_revised/signup_template.html) [function.file-get-contents]: failed to open stream: No such file or directory in /home/disorder/public_html/inc/php/functions.php on line 9

      Warning: file_get_contents(/home/disorder/public_html/dev/tutorials/email_signup/source_revised/signup_template.html) [function.file-get-contents]: failed to open stream: No such file or directory in /home/disorder/public_html/inc/php/functions.php on line 9

      if you want u can see the demo here > http://www.campusbd.com/new/

      pleas help matt . If you could help me that would be great

      Thanks!

  • http://cresignsys.com abey

    Warning: file_get_contents(C:/xampp/htdocs/dev/tutorials/email_signup/source_revised/signup_template.html) [function.file-get-contents]: failed to open stream: No such file or directory in C:\xampp\htdocs\signup\inc\php\functions.php on line 9

    Warning: file_get_contents(C:/xampp/htdocs/dev/tutorials/email_signup/source_revised/signup_template.txt) [function.file-get-contents]: failed to open stream: No such file or directory in C:\xampp\htdocs\signup\inc\php\functions.php on line 9

    Warning: mail() [function.mail]: Failed to connect to mailserver at “localhost” port 25, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set() in C:\xampp\htdocs\signup\inc\php\swift\classes\Swift\Transport\SimpleMailInvoker.php on line 50

    hot to correct this waning

  • Chris

    great code, thanks, i am having one slight issue though, everything seems to run though fine, and the email gets sent, but on the webpage after the signup now button has been pressed, i get the following text:

    Warning: mail() [function.mail]: Policy restriction in effect. The fifth parameter is disabled on this system in /customers/bellasboutiqueonline.co.uk/bellasboutiqueonline.co.uk/httpd.www/test/inc/php/swift/classes/Swift/Transport/SimpleMailInvoker.php on line 50

    what does this mean?

    secondly has anyone created a unsubscribe link to attach to emails?

    many thanks in advance, and as i said great tut

    Chris

  • Alex

    I’m having a lot of trouble getting the e-mail to be sent out. Figured out and improved everything else but I can’t for the sake of hell get the thing to actually send me a mail:

    $var = send_Email($info);
    var_dump($var);

    The code above gives me int(0). I don’t know if that’s what I’m supposed to get although I doubt it. But it still doesn’t make a difference. I’m not getting any mails.

    So my question is, <strong>Could you speciffy any resources or links to your e-mail sending code if you are providing any somewhere? thanks a million</strong>

  • 1nfopro.com

    “Could not send confirm email” This is the error code i am getting after submitting all my information. I don’t know why!? I’ve tried everything but if I try to fix it, I get plenty of other error codes. All I need to know is what I have to change in the code so It’ll work. The code i used is the exact same code that was provided with the tutorial, except for ereg_ that I changed to preg_… Thanks in advance!

  • http://jeronimocosio.com Cosio55

    Hi, this is really an excellent tutorial, but a bit too much for what i need, i would like to know of a very easy tutorial you may know about, that could let me just fill a MySql table from a registration form?, i dont need to validate any users or create any password. It is just to create a registration form for a wedding, really thanks in advance!

  • http://www.ventesdegaragebsl.com Patrice

    Is it normal that the images doesn’t shows up in Gmail? I did create the .gif and place it in the good folder.. But even if I click “Always show images from this person” Nothing happen.

    Any ideas?

    • http://www.ventesdegaragebsl.com Patrice

      Just figured it out..

      We need to place an absolute link instead of /img/yourpicture.jpg

      Exemple : background=”http://www.yoursite.com/folder/img/yourpicture.jpg”

      Nice tutorial, I will now adpated it to validate the fields and keep the values in input when there is an error.

  • http://www.secondgenerationdesign.com/ Delbert Johnson

    i get confused at step 9 what do i do from there?

  • patrice

    i did not understand can you tell me about 000webhost.com that how can i add login and signup syestem to my site my site is from http://www.co.cc i host from 000webhost.com can you tell i obey your steps but it did not work

  • Gjosse

    I can not go past Step 3, i do not know what to put in for localhost because i am using zymic so i don;t know what local host is!
    Can any one help?
    Thanks
    GJosse

  • Acezon Cay

    I also have this “Could not send confirm email” error. When I checked my database, all the information was saved but then, I’m not receiving the confirmation email. I can’t seem to find the error in my code. Thanks for your help.

  • GamerX

    How can i inplant a login system and logout button with this?
    I’ve tried myself several times, but I’ve just failed hard :(

  • Bilal Bakht

    Nothing happens. Even if I leave it blank. Or enter everything. Even in the source.

  • KaHos

    Could not send confirm mail

    what now ?

  • Projeycb

    Whoaaa dude!!! It is soo complicated I just use a form builder maaan go check it out! http://www.jotform.com/

  • http://24 jamhilxon

    i need code

  • step

    owesome. thanks for this tutorial

  • http://divinedesigns1.net dwayne

    i keep on getting this error from after i upload the php version of the script

    mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/05/8364905/html/signupck.php on line 40
    Database Problem, please contact Site admin

    what does this mean?

  • Bosko

    Hello,
    I want to implement your script into my website but I get this error on submit.
    Data is insert into database but I still get this error:
    Fatal error: Interface ‘Swift_Mime_HeaderSet’ not found in …….. /php/swift/classes/Swift/Mime/SimpleHeaderSet.php on line 32.
    Can somebody help mw with this error.I can found reason for that error.
    Thank you in advance.

    Bosko

  • vikas

    my login screen is working fine …..
    but the mail i received is blank not with content..
    Please help

  • ali

    set ur directory by ur self , where u place confirm.php , my confirm.php store in to reg_form directory , and u check by ur self ,
    //set the root
    $root = $_SERVER['DOCUMENT_ROOT'].’/reg_form’;

    but right now my problem i got cofirm link , but when i click on that , problem loading page , “Error occured ” is there any one guide me ,where is the problem in code

    thank

    regards

    Ali

  • ali

    now its work, thnks very nice , toturial , thanks again , sir nice work , is there any same kind of login code ,

  • http://www.privatemwo.com GM Alendros

    followed the instructions step by step and got this error
    Deprecated: Function ereg_replace() is deprecated in C:\Documents and Settings\Owner\Desktop\xampp\xampp\htdocs\inc\php\functions.php on line 12

    Deprecated: Function ereg_replace() is deprecated in C:\Documents and Settings\Owner\Desktop\xampp\xampp\htdocs\inc\php\functions.php on line 13

    Deprecated: Function ereg_replace() is deprecated in C:\Documents and Settings\Owner\Desktop\xampp\xampp\htdocs\inc\php\functions.php on line 14

    Deprecated: Function ereg_replace() is deprecated in C:\Documents and Settings\Owner\Desktop\xampp\xampp\htdocs\inc\php\functions.php on line 15

    Deprecated: Function ereg_replace() is deprecated in C:\Documents and Settings\Owner\Desktop\xampp\xampp\htdocs\inc\php\functions.php on line 12

    Deprecated: Function ereg_replace() is deprecated in C:\Documents and Settings\Owner\Desktop\xampp\xampp\htdocs\inc\php\functions.php on line 13

    Deprecated: Function ereg_replace() is deprecated in C:\Documents and Settings\Owner\Desktop\xampp\xampp\htdocs\inc\php\functions.php on line 14

    Deprecated: Function ereg_replace() is deprecated in C:\Documents and Settings\Owner\Desktop\xampp\xampp\htdocs\inc\php\functions.php on line 15

    Warning: mail() [function.mail]: Failed to connect to mailserver at “localhost” port 25, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set() in C:\Documents and Settings\Owner\Desktop\xampp\xampp\htdocs\inc\php\swift\classes\Swift\Transport\SimpleMailInvoker.php on line 50

    i already have a signup page created with php/html scripts i wanted this one because of the email function so i do have good knowledge of this cannot figure out this error for the life of me

  • http://www.privatemwo.com GM Alendros

    followed the instructions step by step and got this error
    Deprecated: Function ereg_replace() is deprecated in C:\Documents and Settings\Owner\Desktop\xampp\xampp\htdocs\inc\php\functions.php on line 12

    Deprecated: Function ereg_replace() is deprecated in C:\Documents and Settings\Owner\Desktop\xampp\xampp\htdocs\inc\php\functions.php on line 13

    Deprecated: Function ereg_replace() is deprecated in C:\Documents and Settings\Owner\Desktop\xampp\xampp\htdocs\inc\php\functions.php on line 14

    Deprecated: Function ereg_replace() is deprecated in C:\Documents and Settings\Owner\Desktop\xampp\xampp\htdocs\inc\php\functions.php on line 15

    Deprecated: Function ereg_replace() is deprecated in C:\Documents and Settings\Owner\Desktop\xampp\xampp\htdocs\inc\php\functions.php on line 12

    Deprecated: Function ereg_replace() is deprecated in C:\Documents and Settings\Owner\Desktop\xampp\xampp\htdocs\inc\php\functions.php on line 13

    Deprecated: Function ereg_replace() is deprecated in C:\Documents and Settings\Owner\Desktop\xampp\xampp\htdocs\inc\php\functions.php on line 14

    Deprecated: Function ereg_replace() is deprecated in C:\Documents and Settings\Owner\Desktop\xampp\xampp\htdocs\inc\php\functions.php on line 15

    Warning: mail() [function.mail]: Failed to connect to mailserver at “localhost” port 25, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set() in C:\Documents and Settings\Owner\Desktop\xampp\xampp\htdocs\inc\php\swift\classes\Swift\Transport\SimpleMailInvoker.php on line 50

    i already have a signup page created with php/html scripts i wanted this one because of the email function so i do have good knowledge of this cannot figure out this error for the life of me

  • ali

    edit ur function page , and paste directory path , as well

  • Eoghan

    I keep getting this error:
    Parse error: syntax error, unexpected T_NS_SEPARATOR in /Applications/MAMP/htdocs/SignUpForm/inc/php/functions.php on line 50

    The line it is referring to is:

    $error = ” ” . “\n”;

    This is from step 12 in functions.php

    I have searched and searched but I cannot find the solution. Can anyone help me? Or is this tutorial too old now for me even to get a reply? Please help!

    • Eoghan

      Whoops forgot to replace my brackets, here is the line the error is reffering to:
      $error = “<ul class=”\”alert” $action[result]\”=”">” . “\n”;

  • http://imameira.andipangeran.com/ Andi

    I’ve tried to follow the step by step tutorial, it works good until i got an email confirmation and i clicked the link and sent me to “500 Internal Server Error”

    Please help, Thanks :)

  • Eoghan

    Lots of syntax errors in this

  • zeffa

    i’m stacked in step3…
    cannot connect to database…
    someone….help me….

  • http://farsing pia ahbey

    i hate this is main koi info nai hai un info website :( hite this

  • shouldi

    OK, how do i get past this ??

    Warning: mail() [function.mail]: Failed to connect to mailserver at “localhost” port 25, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set() in F:\Xampp\htdocs\4\inc\php\swift\classes\Swift\Transport\SimpleMailInvoker.php on line 50

    I mean i have been reading for hours, and trying tons of different ways to send a confirmation e-mail, or any e-mail in that matter , but still all comes to the mailserver problem. I tried starting my own mail server , but it seems the free ones cant relay messages outside of the local network, so they are pretty much useless, except for testing purposes only. So my question is … what do i have to do to make this problem go away??? I tried using “smtp.googlemail.com” (not localhost) as smtp server but there comes another problem :
    “Must issue a STARTTLS command first. 53sm74258444eef.2″

    which i find unresolvable again …

  • Saikat Das

    Please tell me if this validation is possible using C# in Visual Studio…..

    If yes please provide the code…

  • Javad

    Itz very useful thnx yaaaaaaaa…

    http://www.facebook.com/jvdmhmd

  • WebmasterNeel

    Well……….

    After dedicated 3 hrs., finally I made it up and working…

    All the game is to be played at function.php.

    Be actual about the SETPATH thing…and you’re done.

    Thanks and Regards.

    Hope to see more from you in future.

  • http://www.lateralaus.com Phillip

    Great tutorial, I can’t understand why so many people are having issues with it. My only beef is that it doesn’t seem to deal with duplicate usernames. Did I miss something, or can anyone recommend the best way to deal with this?

  • ashley

    hi there!! can anybody tell me how to edit “function.php” i get error…i think i have problem setting up root folder..i try all but still i get error…plz help

  • ashley

    I get this error…..plz hepl!!!

    Warning: file_get_contents(C:/xampp/htdocs/myfristwebsite//signup_template.html) [function.file-get-contents]: failed to open stream: No such file or directory in C:\xampp\htdocs\MyFirstWebsite\inc\php\functions.php on line 9

    Deprecated: Function ereg_replace() is deprecated in C:\xampp\htdocs\MyFirstWebsite\inc\php\functions.php on line 12

    Deprecated: Function ereg_replace() is deprecated in C:\xampp\htdocs\MyFirstWebsite\inc\php\functions.php on line 13

    Deprecated: Function ereg_replace() is deprecated in C:\xampp\htdocs\MyFirstWebsite\inc\php\functions.php on line 14

    Deprecated: Function ereg_replace() is deprecated in C:\xampp\htdocs\MyFirstWebsite\inc\php\functions.php on line 15

  • Sandra

    I have gotten half way through Step5 I copied the entire contents of the downloaded files to my www folder in wamp. But have come across the following errors. The data entered (name password and email are all submitted to the database but these errors appear when I click ‘signup now’ :

    Warning: require_once(C:\wamp\www\inc\php\swift/swift_init.php) [function.require-once]: failed to open stream: No such file or directory in C:\wamp\www\inc\php\swift\swift_required.php on line 35

    and

    Fatal error: require_once() [function.require]: Failed opening required ‘C:\wamp\www\inc\php\swift/swift_init.php’ (include_path=’.;C:\php\pear’) in C:\wamp\www\inc\php\swift\swift_required.php on line 35

    Any help woyud be much appreciated :)

  • http://www.ultimateinside.in Jagan

    mysql_connect(‘localhost’, ‘username’, ‘password’) or die(“I couldn’t connect to your database, please make sure your info is correct!”);

    What should i add in the place of “username” and “password”?

  • http://localhost Jabry

    I copied the downloaded files to my www folder in easyPHP. But have the following errors.The data entered (name password and email are all submitted to the database but these errors appear when I click ‘signup now’ :

    Warning: file_get_contents(C:/Archivos de programa/EasyPHP-5.3.9/www/dev/tutorials/email_signup/source_revised/signup_template.html) [function.file-get-contents]: failed to open stream: No such file or directory in C:\Archivos de programa\EasyPHP-5.3.9\www\dev\inc\php\functions.php on line 9

    Deprecated: Function ereg_replace() is deprecated in C:\Archivos de programa\EasyPHP-5.3.9\www\dev\inc\php\functions.php on line 12

    Deprecated: Function ereg_replace() is deprecated in C:\Archivos de programa\EasyPHP-5.3.9\www\dev\inc\php\functions.php on line 13

    Deprecated: Function ereg_replace() is deprecated in C:\Archivos de programa\EasyPHP-5.3.9\www\dev\inc\php\functions.php on line 14

    Deprecated: Function ereg_replace() is deprecated in C:\Archivos de programa\EasyPHP-5.3.9\www\dev\inc\php\functions.php on line 15

    Warning: file_get_contents(C:/Archivos de programa/EasyPHP-5.3.9/www/dev/tutorials/email_signup/source_revised/signup_template.txt) [function.file-get-contents]: failed to open stream: No such file or directory in C:\Archivos de programa\EasyPHP-5.3.9\www\dev\inc\php\functions.php on line 9

    Deprecated: Function ereg_replace() is deprecated in C:\Archivos de programa\EasyPHP-5.3.9\www\dev\inc\php\functions.php on line 12

    Deprecated: Function ereg_replace() is deprecated in C:\Archivos de programa\EasyPHP-5.3.9\www\dev\inc\php\functions.php on line 13

    Deprecated: Function ereg_replace() is deprecated in C:\Archivos de programa\EasyPHP-5.3.9\www\dev\inc\php\functions.php on line 14

    Deprecated: Function ereg_replace() is deprecated in C:\Archivos de programa\EasyPHP-5.3.9\www\dev\inc\php\functions.php on line 15

    Warning: mail() [function.mail]: Failed to connect to mailserver at “127.0.0.1″ port 25, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set() in C:\Archivos de programa\EasyPHP-5.3.9\www\dev\inc\php\swift\classes\Swift\Transport\SimpleMailInvoker.php on line 22

  • Aneeq

    Sometimes we need to download files as attachment in PHP. This code can ideally be called on a hyperlink.

    $filename = “myImage.jpg”;

    if(file_exists($filename)) {

    header(“Content-disposition: attachment; filename={$filename}”);

    //Tell the filename to the browser

    header(‘Content-type: application/octet-stream’);

    //Stream as a binary file! So it would force browser to download

    readfile($filename);

    //Read and stream the file

    }else{

    echo “Sorry, the file does not exist!”;

    }

    ——————–

    Source:

    http://phphelp.co/2012/06/13/how-to-stream-a-file-as-attachment-in-php/

    OR

    http://addr.pk/a988

  • http://www.rock-smile.com hk

    I am stuck at step 4. When I put the code in index.php, my entire website crashes and I get php error which I cannot correct again. So I have to start from step 1 all over again. (I am using online website builder http://www.000webhost.com). So as it said, I created a separate php file for step 4 and uploaded it to public_html folder. Now in step 5, I don’t know where to enter these codes. Should I make php files with these codes and upload it to public_html folder or should it be integrated with any other php files. Any help with this will be grateful. I am a beginner and don’t know anything about codes.

    Thank you!!!!