November 10, 201016 yr 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.
November 10, 201016 yr 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