March 20, 20179 yr Hi Folks, I am having some issues in getting our form to work, and I am hoping someone can help. I have used a customised script which I have altered but am still experiencing issues in getting the form to work once a user clicks on 'send message' button. Is there a simple script i can upload and change, or is there something I need to change to the existing script - see below. Any help or advice would be appreciated. <?php /* Set e-mail recipient */ $myemail = "dan@definitelydomains.com"; /* Check all form inputs using check_input function */ $name = check_input($_POST['Name']); $email = check_input($_POST['Email']); $offerinquiry = check_input($_POST['Offer Inquiry']); /* If e-mail is not valid show error message */ if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) { show_error("E-mail address not valid"); } /* If URL is not valid set $website to empty */ if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $website)) { $website = ''; } /* Let's prepare the message for the e-mail */ $message = "Hello! Your contact form has been submitted by: Name: $name E-mail: $email Offer Inqury: $offerinquiry End of message "; /* Send the message using mail() function */ mail($myemail, $name, $email $offerinquiry); /* Redirect visitor to the thank you page */ header('Location: thanks.htm'); exit(); /* Functions we used */ function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?> <html> <body> <b>Please correct the following error:</b><br /> <?php echo $myError; ?> </body> </html> <?php exit(); } ?>
March 20, 20179 yr Beyond simple is this: https://formspree.io/ 3 lines of html and it just works. No more messing with contact forms. I keep thinking there must be a catch Edited March 20, 20179 yr by TimW
March 20, 20179 yr Author Thank you - I will check this out. I have added a simple script in the meantime which seems to have worked to a degree. I am now able to receive the email once someone hits 'Send message', but how do i alter this script to include additional comments? The amended script i am using is below - <?php $ToEmail = 'dan@definitelydomains.com'; $EmailSubject = 'DrivingSupercars'; $mailheader = "From: ".$_POST["email"]."\r\n"; $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; $MESSAGE_BODY = "Name: ".$_POST["name"].""; $MESSAGE_BODY .= "Email: ".$_POST["email"].""; $MESSAGE_BODY .= "Offer Inquiry: ".nl2br($_POST["offer_inquiry"]).""; mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); ?>
Create an account or sign in to comment