Using the information in this tutorial you can make a mailing list in PHP and you can do this with any website template to create a contact form or if you want to create a mailing list kind of thing for your self in the back-end of your website.
To process an email you need to follow the following steps I will be making a post for each one of these steps:
- Create a form to get the email
- validate the email details
- send the email Part 1 (To one recipient)
- send the email Part 2 (To all recipients)
Creating a form to get the email details. for this step we can use and HTML form to do this for us so here is the basic code (you can style this or add or remove fields from it) code that you can put inside your PHP or HTML file:
<form action=”mail.php” method=”get”>
<label for=”email”>email</label><input type=”text” name=”email” /><br />
<label for=”cc”>cc</label><input type=”text” name=”cc” /><br />
<label for=”subject”>subject</label><input type=”text” name=”subject” /><br />
<label for=”Message”>Message</label><textarea name=”Message”></textarea><br />
<input type=”submit” value=”Send” /><input type=”reset” />
This will give you a form like the one bellow(I have disabled the send button in the example bellow):
Now let me explain what each line of code means if you don’t need this part move to Step 2
we first creating a form using the HTML tag <form>
inside this form we will have different fields that we will use not the form tag will send the data on these fields to the file “mail.php” which is in the same web folder as this form is in(or HTML file that has the form on it).
Then I created a label for the fields that I am making so the user will know what fields means what we do this using the <label> tag and you will tell it for=”email” means this label is for field “name” and what ever you put between the <label></label> tags will be shown on the form.
Now we are creating fields using <input> tag and we give it a name so <input type=”text” name=”email” /> means create a field that its type is text meaning it is a single line to input one entry) and I call it “email”.
The rest are pretty the same with one exception and that is the Message because message can be long and can be entered by user in multiple lines we will be using a text area using the tag<textarea>some text</textarea>.
and two buttons, the send button will be used to send the email while the reset one well it will reset the form, and here is the part that you can be creative if you put some value inside each one at the beginning of creating the form and inside the HTML tags, when the user resets it will go back to those values.
you can do this for text boxes using the value=”some text” inside the tag so your email tag for example would be <input type=”text” name=”email” value=”some text” /> to put “some text” inside the field email and for textarea tag just put the text between the two open and close tags like <textarea>some text</textarea>
now for the buttons all you so you set the type to “submit” for sending the form data to “mail.php” and to clear all fields put “reset”. to put the send text in the submit button just put it inside the value=”the text” format for that button and you are set.
Now to Step 2.