Wednesday 20 April 2011

Email contact form in php

<html>
<head>
<script src="calendar.js"></script>
<style>
input {border:1px solid #ABABAB}
</style>
</head>
<body>

<?php

$t=$_GET['to'];
if ($t=="m")
//if "email" is filled out, send email
{
$t="to@mail.com";
}
else
//if "email" is not filled out, display the form
{
$t="your@mail.com";
}

?>

<form method='post' action='mailform.php'>

<input name='to' type='hidden' value='<?php echo $t; ?>' />

Email: &nbsp;&nbsp;
<input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Date &nbsp;&nbsp; :
<input name='todate' onclick="event.cancelBubble=true;this.select();lcs(this)" onfocus="this.select();lcs(this)" type="text" value="dd/mm/yy" /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='submit' />
</form>

</body>
</html>

mailform.php

<?php

$to = $_REQUEST['to'];
$subject = "New Appointment on ".$_REQUEST['todate'];
$message = $_REQUEST['message'];
$from = $_REQUEST['email'];
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent to the concerned doctor.";

?>

No comments:

Post a Comment