The PHP mail() function is handy. You can use it to have people contact you through a form on your Web page if you don’t feel comfortable displaying your email address. The sample code below will send an email to “contact@mydomain.com” with the subject and message as the respective text inputs below.
<?php// check to see if send button has been clickedif (isset($_REQUEST["submit"])) {
$to = "contact@mydomain.com";
$from = $_REQUEST["email"];
$subject = $_REQUEST["subject"];
$message = $_REQUEST["message"];
// validate email addressif (!filter_var($from, FILTER_VALIDATE_EMAIL)) {
$err_from = true;
}if ($err_from) {
// error message goes here} else {
// try to send itif (mail($to, $subject, $message, "From: $from")) {
// message has been sent} else {
// there's been an error}}}?><form method="post" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>">
<p><label>From:<br /><input name="email" type="text" value="<?php echo $from; ?>" /></label></p>
<p><label>Subject:<br /><input name="subject" type="text" value="<?php echo $subject; ?>" /></label></p>
<p><label>Message:<br /><textarea name="message" rows="10"><?php echo $message; ?></textarea></label></p>
<p><input name="submit" type="submit" value="Send" /></p>
</form>








