PHP feedback form not validating or submitting

Ok ... so I grabbed this PHP contact form from a combination of several different sites and from the predecessor. I fought with him for hours and cannot understand.

In fairness, know that PHP is not my strong suit, in general (I am a client-side programmer). Here is the code below, please help if you can. Thanks!

Here are some of the error messages I saw:

Most recent: * Parse error: syntax error, unexpected T_IF in / home / [...] on line 11 *

Before that there was an error message, but I believe that I fixed the "empty field" part:

It looks like you left an empty field.

Please make sure that you fill in your full name, email address, subject and details. Click the back arrow to return to the contact form.

From: ... List :; syntax illegal for recipient addresses

Reply-To: ... List :; syntax illegal for recipient addresses

X-Mailer: ... List :; syntax illegal for recipient addresses

Thank you [name] for contacting us!

Here is the HTML

<form action="contactus.php" method="post" class="create"> <fieldset> <legend align="center">Please fill out details below and click "Submit"</legend> <div> <label for="fullname" class="fixedwidth">Full Name</label> <input type="text" name="fullname" id="fullname" class="input2"/> </div><br/> <div> <label for="email" class="fixedwidth">Email</label> <input type="text" name="email" id="email" class="input2"/> </div><br/> <div> <label for="subject" class="fixedwidth">Subject</label> <input type="text" name="subject" id="subject" class="input2"/> </div><br/> <div> <label for="details" class="fixedwidth">Body</label> <textarea id="details" name="details" cols="62" rows="20"></textarea> </div> <div class="buttonarea"> <input type="submit" name="submit" id="submit" value="Submit"/> </div> </fieldset> </form> 

... and here is the contactus.php file:

 <?php $fullname = $_POST['fullname']; $subject = $_POST['subject']; $details = $_POST['details']; $email = $_POST['email']; //*** Function to check email address */ function checkemail($email) { $regex = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)@[a-z0-9-]+(\.[a-z0-9-]+)(\.[az]{2,3})$/' if (eregi($regex ,$email)) { return true; } else { return false; } } //*** Check to see if the email address is valid */ else if (checkemail($email) == false) { echo "<br/><br/><p><center>It appears that you have entered an invalid email address.<br/> Please check your email again.</p>"; } //*** Mail Processing */ if ($_POST['submit']) { //Check for blank fields if ($fullname !== "" && $email !== "" && $subject !== "" && $details !== "") { echo "<br/><br/><p><center>It appears that you left a blank field.<br/> Please make sure you fill in your full name, email address, subject, and details.<br/> Click the back arrow to return to the contact form.</p>"; } //*** Send Mail**/ $to = ' sgraffito22@gmail.com '; $fullname = $_POST['fullname']; $subject = $_POST['subject']; $details = $_POST['details']; $headers = 'From: '.$email."\r\n". 'Reply-To: '.$email."\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $fullname, $subject, $details, $headers); echo "<br><br><p><center>Thank you, $fullname, for contacting us!</p><br><br>"; } ?> 
+1
source share
2 answers

You are missing ; in the end

 $regex = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)@[a-z0-9-]+(\.[a-z0-9-]+)(\.[az]{2,3})$/' 

Syntax errors From , Reply-to and X-Mailer can be caused by switching between ' and " in $headers

 $headers = 'From: '.$email."\r\n". 'Reply-To: '.$email."\r\n" . 'X-Mailer: PHP/' . phpversion(); 

try changing to -

 $headers = "From: ".$email."\r\n"; $headers .= "Reply-To: ".$email."\r\n"; $headers .= "X-Mailer: PHP/" . phpversion(); 
0
source

Since the regex solution was asked by Sean,

Here is my previous regex project that I used,

 $regex= "/^[\.a-z0-9_\-]+[@][a-z0-9_\-]+([.][a-z0-9_\-]+)+[az]{1,4}$/i"; 

This is another alternative for the PHP mailing list, you will need to download the phpmailer plugin for this mailing list to work.

 <?php // mail config start $emailAddress = 'youremailhere'; $replyAdress ='yourreceipientemailhere'; $replyName = 'yourreceipientname'; $msgSubject= 'yoursubjecthere'; // mail config end // Include the class, require "phpmailer/class.phpmailer.php"; //Type your message here: $msg = 'blablayourmessagehere'; //The mailing process begins!! $mail = new PHPMailer(); $mail->IsMail(); $mail->AddReplyTo($replyAdress, $replyName); $mail->AddAddress($emailAddress); $mail->SetFrom($replyAdress, $replyName); $mail->Subject = "New: ".$replyName." have sent a ".$msgSubject." message"; $mail->MsgHTML($msg); $mail->Send(); ?> 
0
source

All Articles