web 2.0

How to use PHP & Send Email Contact Form

How to use PHP & Send Email Contact Form This the tutorial/example a scripts how to use PHP and send mail/email with Contact Form from php Scirpt.

ShotDev Focus:
- PHP & Send Mail (Contact Form)

Example

php_sendmail_contact1.php

  1. <html>  
  2. <head>  
  3. <title>ShotDev.Com Tutorial</title>  
  4. </head>  
  5. <body>  
  6. <form action="php_sendmail_contact2.php" method="post" name="form1">  
  7. <table width="343" border="1">  
  8. <tr>  
  9. <td>To</td>  
  10. <td><input name="txtTo" type="text" id="txtTo"></td>  
  11. </tr>  
  12. <tr>  
  13. <td>Subject</td>  
  14. <td><input name="txtSubject" type="text" id="txtSubject"></td>  
  15. </tr>  
  16. <tr>  
  17. <td>Description</td>  
  18. <td><textarea name="txtDescription" cols="30" rows="4" id="txtDescription"></textarea></td>  
  19. </tr>  
  20. <tr>  
  21. <td>Form Name</td>  
  22. <td><input name="txtFormName" type="text"></td>  
  23. </tr>  
  24. <tr>  
  25. <tr>  
  26. <td>Form Email</td>  
  27. <td><input name="txtFormEmail" type="text"></td>  
  28. </tr>  
  29. <tr>  
  30. <td>&nbsp;</td>  
  31. <td><input type="submit" name="Submit" value="Send"></td>  
  32. </tr>  
  33. </table>  
  34. </form>  
  35. </body>  
  36. </html>  

php_sendmail_contact2.php

  1. <html>  
  2. <head>  
  3. <title>ShotDev.Com Tutorial</title>  
  4. </head>  
  5. <body>  
  6. <?  
  7. $strTo = $_POST["txtTo"];  
  8. $strSubject = $_POST["txtSubject"];  
  9. $strHeader = "Content-type: text/html; charset=utf-8\n";  
  10. $strHeader .= "From: ".$_POST["txtFormName"]."<".$_POST["txtFormEmail"].">\nReply-To: ".$_POST["txtFormEmail"]."";  
  11. $strMessage = nl2br($_POST["txtDescription"]);  
  12. $flgSend = @mail($strTo,$strSubject,$strMessage,$strHeader);  // @ = No Show Error //  
  13. if($flgSend)  
  14. {  
  15. echo "Mail send completed.";  
  16. }  
  17. else  
  18. {  
  19. echo "Cannot send mail.";  
  20. }  
  21. ?>  
  22. </body>  
  23. </html>  

Create a php file and save to path root-path/myphp/

Run
http://localhost/myphp/php_sendmail_contact1.php

Screenshot

PHP Send Mail (Contact Form)

PHP Send Mail (Contact Form)

.
.
.

Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 1.00 out of 10)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.