Jump to content

Creating a mailing list tutorial


kishou

Recommended Posts

Mailing list Tutorial by kishounote: don't copy or reproduce this in any shape or form. or sell this.In this tutorial i will teach you how to create a mail list in MySQL and PHP. So users on your site can stay up to date with you.1. If you dont have a website. Go here: http://x10hosting.com/ and get one for free. thats the one im using in this tutorial.2. Go to your cPanel and then go click "MySQL Databases" and create a new database called whateveryouwantto.3. Go back to your cPanel and then click "phpmyadmin" and go click the name of your database which is on the left hand side. Then create a table called "mailing_list". Then in the number of fields but 1. And we only want 1 because we only want the email.4. This pic shows you what i mean:example.JPG5. Now create a file called mailinglist.html and put in it this code:

<html><head><title>Mailing List<title></head><body>Add your email to the mailing list!<form action="mailinglist.php" method="post"> <! --In here we do the method post cause it's more secure than "get". we also call for the file "mailinglist.php" so in that file it adds the user to the mailing list.-- !>Email:<input type="text" name="email"> <! --This is the textbox where the user enters his Email-- !><input type="Submit" value="Submit"> <! --This is the button that the user presses to have his/her email added.-- !></form></body></html>

6. In the same folder that the html file is in make a new file called mailinglist.php and in it put this code in it:

<html><head><title>Mailing List</title></head><body><?php$connect = mysql_connect("localhost", "usernameofdatabase", "passwordofdatabase");//In this line we want us to connect with our Database. Also for "localhost" leave that but change "username" and "password to your username and password and put it in there"if (!$connect)// In this statement its saying if it cant connect to the database then it prints couldnt connect to Database.{die('Couldnt connect to Database');}mysql_select_db("yourdatabase", $connect);// in this line we select the database we want to connect to.$res=mysql_query("SELECT * FROM mailing_list where Email='".$_POST[email]."'"); // in this part we check if the email the user inputted is already in the table.if (mysql_num_rows($res)>0) //if there's more than one value in table with the same email in the database we print you have already subscribed and then it doesnt add the person to the database.{echo "You've already subscribed!";}else //but this is what it does when there is no email with the email the user inputted. it. $sql="INSERT INTO mailing_list (Email) //Now this part it inserts the thing the user inputted into the table mailing list that we already created in the the Email field that we create earlier.VALUES('$_POST[email]')";if (!mysql_query($sql,$connect)){die('Error: ' . mysql_error());} // In thiis part we insert into our table mailinglist andd into our column email.//In thiss part we put the value the user inputted which was named email as seen from the HTML form.$to = "$_POST[email]"; //this tells us who to send it to and in this case its the users input$subject = "Successfully Added!"; //This tells us the subject of the email$message = "Hello! You have successfully subscribed to youwebsite.com!"; //This is whats in the email$from = "mailinglist@something.com"; //This tells us who its from$headers = "From: $from"; //whats going to be in the head.mail($to,$subject,$message,$headers); //This part mails the email with the above information we declaredecho "Successfully added your email! Check your email!"; //So if it works it outputs Successfully added your email check your emailmysql_close($connect); //in this part we close our mysql connection cause we arent using it anymore?></body></html>

7. You can also check to see the emails of people that put their emails in it by going to "phpmyadmin" and go to your database --> click the browse button right by the name of your talbe on the right hand side of it and then click export ---> and it'll sow the values or emails of all the ppl registered.or You can also check it by going to "phpmyadmin" and go to your database --> click export --> then select pdf -->click go.If you have any questions about this tutorial don't hesistate to post it here. :)working example: http://www.pspstuff.elementfx.com/mailinglist.html

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...