hello please send code for autoreply of email in contact form my contact form is :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Welcome </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style.css" rel="stylesheet" type="text/css">
<SCRIPT>//global variable for error flag
var errfound = false;
//function to validate by length
function ValidLength(item, len) {
   return (item.length >= len);
}
//function to validate an email address
function ValidEmail(item) {
   if (!ValidLength(item, 5)) return false;
   if (item.indexOf ('@', 0) == -1) return false;

   return true;
}
// display an error alert
function error(elem, text) {
// abort if we already found an error
   if (errfound) return;
   window.alert(text);
   elem.select();
   elem.focus();
   errfound = true;
}
// main validation function
function Validate() {
   errfound = false;
   if (!ValidLength(document.form.contact_name.value,1))
      error(document.form.contact_name,"Enter Your  Name");
       if (!ValidEmail(document.form.contact_email.value,1))
      error(document.form.contact_email,"Enter Your Email Id");

      if (!ValidLength(document.form.contact_phone.value,1))
      error(document.form.contact_phone,"Invalid phone number");


     if (!ValidLength(document.form.contact_comments.value,1))
      error(document.form.contact_comments,"Enter Your Comments");




      return !errfound; /* true if there are no errors */
}</SCRIPT>
<SCRIPT language="javascript">
function Only_Num(id) {
    if(isNaN(document.getElementById(id).value)) {
        alert("Please Enter Numbers Only (0-9)..");
        document.getElementById(id).select();
        document.getElementById(id).value=""
        document.getElementById(id).focus();
    }
    return;
}
</SCRIPT>
</head>

<body bgcolor="ffffff" class="ServiceContentBody">

<form name="form" action="submit.php"  onSubmit="return Validate()" method="post">
  <table width="391" border="0" cellpadding="0" cellspacing="2">


    <tr>
      <td width="1" align="left" valign="middle" class="ContactFormText"></td>
      <td width="125" align="right" valign="middle" class="ContactFormText"><div align="right">Name:</div></td>
      <td width="257"><input name="contact_name" type="text" size="35"  ></td>
    </tr>

    <tr>
      <td width="1" align="left" valign="middle" class="ContactFormText"></td>
      <td width="125" align="right" valign="middle" class="ContactFormText"><div align="right">E-mail:</div></td>
      <td><input  name="contact_email"type="text" size="35"></td>
    </tr>

    <tr>
      <td width="1" align="left" valign="middle" class="ContactFormText"></td>
      <td width="125" align="right" valign="middle" class="ContactFormText"><div align="right">Phone:</div></td>
      <td><input name="contact_phone"   size="35" onChange="Javascript:LA()"  onKeyUp="Only_Num(this.id)"id="phone"></td>
    </tr>

    <tr>
      <td width="1" align="left" valign="top" class="ContactFormText"></td>
      <td width="125" height="0" align="left" valign="middle" class="ContactFormText"><div align="right">Comments:</div></td>
      <td height="0" align="left" valign="top"><textarea name="contact_comments" cols="40" rows="4" ></textarea></td>
    </tr>

    <tr align="center">
      <td width="1" valign="top" class="ContactFormText"></td>
      <td width="125" height="22" valign="top" class="ContactFormText"></td>
      <td height="22" align="left" valign="middle" class="ContactFormText"><input name="Submit" type="submit" class="WorkSortList" value="SEND">      </td>
    </tr>
  </table>
</form>
</body>
</html>

Dani AI

Generated

A practical, safe way to add an autoreply is to handle everything server-side: validate and sanitize the POSTed fields, reject header-injection attempts, send the site notification, then send a short autoreply from a fixed no-reply address. As asked for code and noted, PHP can do this natively, but take care with validation and deliverability.

<?php
// minimal safe handler: validate, prevent header injection, send admin + autoreply
function has_header_injection($s){ return preg_match("/[\r\n]/", $s); }

$name    = trim($_POST['contact_name'] ?? '');
$email   = trim($_POST['contact_email'] ?? '');
$phone   = trim($_POST['contact_phone'] ?? '');
$message = trim($_POST['contact_comments'] ?? '');

if (!$name || !$message || !filter_var($email, FILTER_VALIDATE_EMAIL) || has_header_injection($name) || has_header_injection($email)) {
    http_response_code(400);
    exit('Invalid input');
}

$adminTo  = 'you@yourdomain.com';
$adminSub = "Contact form: $name";
$adminBody= "Name: $name\nEmail: $email\nPhone: $phone\n\n$message\n";
$adminHdr = "From: Website <no-reply@yourdomain.com>\r\nReply-To: $email\r\nContent-Type: text/plain; charset=UTF-8\r\n";

mail($adminTo, $adminSub, $adminBody, $adminHdr);

// autoreply
$autoSub  = "Thanks for contacting us";
$autoBody = "Hi $name,\n\nThanks for your message. We'll reply shortly.\n\n-- Support Team";
$autoHdr  = "From: Support <no-reply@yourdomain.com>\r\nContent-Type: text/plain; charset=UTF-8\r\n";

mail($email, $autoSub, $autoBody, $autoHdr, "-fno-reply@yourdomain.com");
echo 'OK';
?>

Notes and cautions: never set From: to the user-supplied address (spoofing and spam filters). Use Reply-To: instead. Always run server-side validation (the client-side JS in the form is helpful but not sufficient). Reject CR/LF characters in header fields to prevent header injection. For production use, prefer an SMTP library (better authentication, TLS, and header handling) rather than plain mail().

References and next steps: use a maintained SMTP library for reliability (example: PHPMailer), follow input-validation best practices (OWASP), and check email format rules in RFC 5322 for header expectations.

PHPMailer
OWASP Input Validation Cheat Sheet
RFC 5322 (Internet Message Format)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.