Hey all,

Need someone to come to my rescue.

I'm creating this website and so far the only issue that I'm having is the contact form.

https://universalittechnologies.com/test/contacts.php

I fill out the information correctly and I get an error saying that I need to go back and fill out the requested information and I don't receive an email from the form

Here is the html code.


<form action="mail/MailHandler.php" method="post" id="contact-form">
                  <div class="contact-form-loader"></div>
                  <fieldset>
                    <label class="name">
                      <input type="text" name="name" id="name" placeholder="Name:"  data-constraints="@Required @JustLetters"  />
                      <span class="empty-message">*This field is required.</span>
                      <span class="error-message">*This is not a valid name.</span>
                    </label>

                <label class="email">
                  <input type="text" name="email"  id="email" placeholder="E-mail:"  data-constraints="@Required @Email" />
                  <span class="empty-message">*This field is required.</span>
                  <span class="error-message">*This is not a valid email.</span>
                </label>
                <label class="phone">
                  <input type="text" name="phone" id="phone" placeholder="Phone:" />
                  <span class="empty-message">*This field is required.</span>
                  <span class="error-message">*This is not a valid phone.</span>
                </label>

                <label class="message">
                <span class="empty-message">*This field is required.</span>
                  <span class="error-message">*The message is too short.</span>
                </label>
                <div class="clear"></div>
                <div>
                  <a href="#" class="btn" data-type="submit">Send e-mail</a>
                </div>
              </fieldset>
              <div class="modal fade response-message">
                <div class="modal-dialog">
                  <div class="modal-content">
                    <div class="modal-header">
                      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                      <h4 class="modal-title">Modal title</h4>
                    </div>
                    <div class="modal-body">
                      You message has been sent! We will be in touch soon.
                    </div>   
                  </div>
                </div>
              </div>
            </form>
          <textarea name="message" placeholder="Message:" data-constraints='@Required @Length(min=20,max=999999)'></textarea>

and the php code

<?php
					$errors = array();

		if(empty($_POST['name'])){
			$errors[] = 'Please enter your name';

		} else {

			echo  "";
		}


		if(empty($_POST['email'])){
			$errors[] = 'Please enter your email';

		} else {

			echo "";

		}

		if(empty($_POST['comments'])){
			$errors[] = 'Please enter your comments';

		} else {
			echo  "";
		}


		  $emailPattern = '/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i';

		  $to = "service@universalittechnologies.com";
		//$to ="atlnycdude23@gmail.com";  // ----> Use this $to email declation just in case in a emergency.

		$subject = 'Sales Inquiries, Potential/ReturningCustomer Related Questions';
		$from = 'Universal IT Technologies';

		$name =  safe(stripslashes( $_POST['name']) );
		$email =  safe($_POST['email'] );
		$phone = safe($_POST['phone'] );
		$cname =  safe ($_POST['cname']);
		$comments = safe(stripslashes($_POST['comments']) );


		$headers = "From: ". $from . "<" . $to. ">\r\n";  
		$headers .= "Reply-To: " . $email . "\r\n"; 
		$headers .= "Return-path: ". $email;


	  	$message .= "Name:  " . $name . "\n";
		$message .= "Email: " . $email . "\n\n";
		$message .= "Phone Number: " . $phone . "\n\n\n";
		$message .= "Company Name:  " . $cname . "\n\n\n\n";
		$message .= "Comments: " . $comments . "\n\n\n\n\n\n\n\n";

		if (count($errors) < 1){ 
    mail($to,$subject,$message,$headers);

	  echo "Thank you so much for your Inquiry. I'm looking forward in serving you soon!"; 
	} else { 
	  echo "Please go back and enter the requested information"; 
	} 


function safe($string) 
{ 
	$pattern = "/\r|\n|\%0a|\%0d|Content\-Type:|bcc:|to:|cc:/i"; 
	return preg_replace($pattern, '', $string); 
}



?>

Please help, thanks!

    You check for $_POST['comments'], but I don't see a form element named 'comments'.

      I would also suggest not using a regex to validate email addresses and instead use [man]filter_var/man with the FILTER_VALIDATE_EMAIL flag. Also no need to echo out an empty string if the value from the form is not empty, so you can omit the else portions of those if statements.

        Write a Reply...