| | |
PHP Sendmail Tutorial
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2005
Posts: 19
Reputation:
Solved Threads: 0
Sending email through PHP
Intro
Thousands of websites use contact forms to communicate with their users. You will have almost certainly seen one if not used one to contact someone. The contact form will take the users information that he or she has filled in then send the data over to our php script for processing. In our case the data will be sent over to us in an email.
Creating the HTML Feedback Form
Below is the HTML code to create our feedback form.
The form will take the email address and message from the user and sends the information to sendmail.php via the form, action="sendmail.php".
The php script will know which piece of information being sent by the input name="" tag. So we know the email will be typed in the email box by the name tag: name="email"
The PHP code to sendmail
Now we have set the form to POST the data to sendmail.php we need to create a new file named “sendmail.php". Once you have created the file you can enter the following code into your empty php file. Don’t worry I’ll explain each line in a moment.
Okay this script will now send email out using php’s sendmail function yeh! Now I’ve got some explaining to do.
Line 2 - 3: These get the data from the form keeping in mind the email form box is named name="email" and the $_GET variable is also called email.
Line 4: This is the clever part that sends the email, The mail() function allows to… specify the email address of the recipient, place the the subject of the email which will appear in the subject line, puts the message of the email which appears in the emails main body and the function allows you to specify the senders email so the recipient can then send a reply if required.
The sendmail function is no way limited to this configuration but as a beginner tutorial this is the minimum information you need to make mail() work.
For more information on the sendmail function then please goto phps sendmail function page.
line 5 - Will display “Congratulations your email has been sent"
I hope the tutorial helps any comments or question as always can be post below.
Intro
Thousands of websites use contact forms to communicate with their users. You will have almost certainly seen one if not used one to contact someone. The contact form will take the users information that he or she has filled in then send the data over to our php script for processing. In our case the data will be sent over to us in an email.
Creating the HTML Feedback Form
Below is the HTML code to create our feedback form.
html Syntax (Toggle Plain Text)
<form method="post" action="sendmail.php"> Email: < input name="email" type="text" /> Message: <textarea name="message" rows="10" cols="30"> </textarea> <input type="submit" /> </form>
The form will take the email address and message from the user and sends the information to sendmail.php via the form, action="sendmail.php".
The php script will know which piece of information being sent by the input name="" tag. So we know the email will be typed in the email box by the name tag: name="email"
The PHP code to sendmail
Now we have set the form to POST the data to sendmail.php we need to create a new file named “sendmail.php". Once you have created the file you can enter the following code into your empty php file. Don’t worry I’ll explain each line in a moment.
php Syntax (Toggle Plain Text)
<? $email = $_GET['email'] ; $message = $_GET['message'] ; mail( "yourname@example.com", "Email Subject", $message, "From: $email" ); print "Congratulations your email has been sent"; ?>
Okay this script will now send email out using php’s sendmail function yeh! Now I’ve got some explaining to do.
Line 2 - 3: These get the data from the form keeping in mind the email form box is named name="email" and the $_GET variable is also called email.
Line 4: This is the clever part that sends the email, The mail() function allows to… specify the email address of the recipient, place the the subject of the email which will appear in the subject line, puts the message of the email which appears in the emails main body and the function allows you to specify the senders email so the recipient can then send a reply if required.
The sendmail function is no way limited to this configuration but as a beginner tutorial this is the minimum information you need to make mail() work.
For more information on the sendmail function then please goto phps sendmail function page.
line 5 - Will display “Congratulations your email has been sent"
I hope the tutorial helps any comments or question as always can be post below.
Last edited by cscgal; Oct 29th, 2006 at 2:23 am. Reason: Added code tags
•
•
Join Date: Feb 2007
Posts: 1
Reputation:
Solved Threads: 0
i followed this tutorial and ran into an error with the stated sendmail.php code.. when i send information through the feedback form although i recieved an email and the address of my choice i didnt recieve any email content apart from the subject.
after some research i found out you need to use $_post instead of $_get
here is my code for sendmail.php
Imperial
after some research i found out you need to use $_post instead of $_get
here is my code for sendmail.php
PHP Syntax (Toggle Plain Text)
<?php $email = $_POST['email'] ; $message = $_POST['message'] ; mail ("<a href="mailto:imperial@sublime.maantok-ent.com">imperial@sublime.maantok-ent.com</a>", "Feedback form results", $message, "From: $email") ; print "Congratulations your email has been sent"; ?>
Imperial
![]() |
Similar Threads
- Avoiding Spam from sendmail.php (Promotion and Marketing Plans)
- php tutorial (PHP)
- Installation of PHP on Windows (PHP)
- PHP-Nuke Tutorial #1: Altering the Header Tags (PHP)
Other Threads in the PHP Forum
- Previous Thread: How to use HTML tags in PHP
- Next Thread: problem with session_start
| Thread Tools | Search this Thread |
apache api array basic beginner binary body broken cakephp class cms code computing confirm cron curl customizableitems database date date/time delete display dynamic echo email error file filter folder form forms forum function functions gc_maxlifetime google headmethod href htaccess html iframe image include ip javascript joomla limit link list login malfunction memmory memory menu mlm msqli_multi_query multiple mycodeisbad mysql navigation oop parameter parsing paypal pdf php phpmysql play query question random recourse recursion regex root script search select seo server sessions snippet source space sql static system table thesishelp trouble tutorial update upload url variable video web webdesign xml youtube





