PHP : Form to Email
With the help of this tutorial you can send mails to a user using a form, as we have discussed in our earlier tutorial, it is very easy to send mails using PHP and any mail server like argosoft mail server.
This tutorial will help you to develop a form which looks like a mail form, with the help of this tutorial you can send mails to any valid user. As the mail function needs the address of the receiver, subject and message as primary requirement, if you miss to enter any of these mail will not be sent and an error message will be generated on the next page. If the address of the recipient is valid and every textbox is filled with proper value mail will be sent.
$to=$_POST['to']; $sub=$_POST['sub']; $msg=$_POST['msg'];
echo "Email has been sent";
<form name="mail" action="<?php $PHP_SELF;?>" method="post">
<tr><td><b>To:</b></td><td><input type="text" name="to"></input></td></tr>
<tr><td><b>Subject:</b></td><td><input type="text" name="sub"></input></td></tr>
<tr><td><input type="submit" value="Submit"></input></td>
<td><input type="reset" value="Reset"></input></td></tr>
(If every field is valid and filled then output will be:)
Email has been sent
(If every field is not valid or filled then an error message will be generated as follows:)
Warning: mail() [function.mail]: SMTP server response: 503 No recipient(s). in C:\wamp\www\phpBasics\PHPmail.php on line 10