PHP scripts and programs for Beginner to Master

php programs, php ready to use scripts & functions, css tutorials, html, javascripts, ajax examples for Beginner to Master

At many places we require the contact us or feedback form to get some input from the user or to get some feedback from the user.
Today i will be showing you how to create a very simple feedback form or contact us form in php with the mail function and without any database.

1) First we will be creating a simple form to accept the user input like name, email and their message or feedback or query.





















Name : "/>
Email : "/>
Message :
 





2) In the form tag we have not specified any action part and we kept action="" in the form tag, so when the form is submitted at that time it will call itself.
So on submit we will execute our code to send the mail.





3) some css for the form and good look.

.textbox,.textarea {
width:300px;
border:solid 2px #00CCFF;
padding:3px;
margin:10px;
}
.error {
background: #FBBFDC;
color:#EF013D;
border:solid 1px;
padding:5px;
margin:5px;
}


4) After the page is submitted we will process the form data.



5) When the form is filled then we will be calling a function sendmail.



Finally, merge all the code to create a simple contact us form or feedback form.
Full source code is here for your reference



.textbox,.textarea {
width:300px;
border:solid 2px #00CCFF;
padding:3px;
margin:10px;
}
.error {
background: #FBBFDC;
color:#EF013D;
border:solid 1px;
padding:5px;
margin:5px;
}




















Name : "/>
Email : "/>
Message :
 



if(isset($_POST["Submit"]))
{
$email = $_POST["email"];
$msg = $_POST["message"];
$username = $_POST["name"];
if($username!="" and $email!="" and $msg!="")
{
sendmail($username,$email,"",$msg,"");
}
else
{
echo "
Fill all the fields ! Thank you.
";
}
}
function sendmail($username,$email,$data,$msg,$footer)
{
$to="youremailidhere";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
//$headers .= "From: ".$from."\r\n";
$headers .= "From: $username <$email>\r\n";
$headers .= "Reply-To: youremailidhere\r\n";

$body="

Dear Admin,

";
$body.="

Message from : $username

";
$body.="

Email id : $email

";
$body.="

Message : $msg

";

$body.="Feedback end

";

if(@mail($to,'feedback from http://programming-in-php.blogspot.com',$body,$headers))
{
echo "Thank you for your valuable feedback !";
}
else
{
echo "
Can't send email ! ! !
";
}
}
?>

I'm reading: Send Feedback or contact via mail function in phpTweet this!

0 comments:

Post a Comment