Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Forms and autoresponders

Featured Replies

Hi,

 

I'm putting a form using the following code on a site. I would like to set up an autoresponder but am not sure where to get the senders email address. The form, as you'll see, already asks them to enter it but I need to collect it in the php so the autoresponder knows where to go.

 

Here's my code:HTML

 

<form method="post" action="contact.php"> 
 <fieldset> 
 <legend>Contact Us:</legend> 
      <p> 
     <label for="name">Name:</label> 
          <input type="text" name="Name" class="txt"/> 
   </p> 
   <p> 
     <label for="emailaddress">Email Address:</label> 
     <input type="text" name="Emailaddress" class="txt"/> 
   </p> 
   <p> 
     <label for="telephone">Telephone:</label> 
     <input type="text" name="Telephone" class="txt"/> 
   </p> 


   <p> 
<label for="enquiry">Enquiry:</label> 
<textarea name="Enquiry"></textarea> 
</p> 
  <br /> 

<p> 
<input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p> 
     </fieldset> 
 </form> 

 

PHP:

<?php
$EmailFrom = "info@myplace.co.uk";
$EmailTo = "info@myplace.co.uk";
$Subject = "Enquiry from website";
$Name = Trim(stripslashes($_POST['Name'])); 
$Emailaddress = Trim(stripslashes($_POST['Emailaddress']));
$Telephone = Trim(stripslashes($_POST['Telephone'])); 
$Enquiry = Trim(stripslashes($_POST['Enquiry'])); 


// prepare email body text
$Body = "";
$Body .= "EmailFrom: ";
$Body .= $EmailFrom;
$Body .= "\n";
$Body .= "Subject: ";
$Body .= $Subject;
$Body .= "\n";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Emailaddress: ";
$Body .= $Emailaddress;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $Telephone;
$Body .= "\n";
$Body .= "Enquiry: ";
$Body .= $Enquiry;
$Body .= "\n";


// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
 print "<meta http-equiv=\"refresh\" content=\"0;URL=messagesent.html\">";
}
else{
 print "<meta http-equiv=\"refresh\" content=\"0;URL=messagenotsent.html\">";

 function check_input($data)
{
   $data = trim($data);
   $data = stripslashes($data);
   $data = htmlspecialchars($data);
   return $data;
}
}
?>

 

Thanks for any advice.

Do you mean that you want to send an email reply? You have a variable for the viewer's email address $Emailaddress so add another email to send to him/her after the first one (shown below) and add a reply message variable:-

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
$reply = "Thank you for your enquiry";
$success = mail($Emailaddress, $Subject, $reply, "From: <$EmailFrom>");

 

I note that you have the same email address in $EmailFrom = "info@myplace.co.uk"; and $EmailTo = "info@myplace.co.uk";

That's a good idea to send the email from you to yourself as the email address will come from the same server as the domain which will avoid your host or ISP thinking that it's spam which they tend to do if the email comes from the viewer's email address via your domain's server.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.