The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Issues with contact form, HTML & php files
xynerate
post Feb 12 2018, 03:15 AM
Post #1





Group: Members
Posts: 1
Joined: 12-February 18
Member No.: 26,591



Thank you for any help in advance:

Website in question : http://travel.melkbostravelandvisa.co.za/

You will see there is a contact form. I hope I am missing something simple but I am unable to get the contact form working, that is no email is being sent. I WOULD BE MOST GRATEFUL for any help.

Rik biggrin.gif

Here are the code snippets in question :

html :

<!-- contact -->
<div class="contact" id="contact">
<div class="container">
<h3 class="heading">Contact</h3>
<form action="" method="post" name="sentMessage" id="contactForm">
<div class="col-lg-4 col-md-4 col-sm-4" data-aos="zoom-in">
<div class="control-group form-group">
<div class="controls">
<label>Full Name:</label>
<input type="text" class="form-control" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block"></p>
</div>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-4" data-aos="zoom-in">
<div class="control-group form-group">
<div class="controls">
<label>Phone Number:</label>
<input type="tel" class="form-control" id="phone" required data-validation-required-message="Please enter your phone number.">
</div>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-4" data-aos="zoom-in">
<div class="control-group form-group">
<div class="controls">
<label>Email Address:</label>
<input type="email" class="form-control" id="email" required data-validation-required-message="Please enter your email address.">
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="col-lg-12" data-aos="zoom-in">
<div class="control-group form-group">
<div class="controls">
<label>Message:</label>
<textarea rows="10" cols="100" class="form-control" id="message" required data-validation-required-message="Please enter your message" maxlength="999" style="resize:none"></textarea>
</div>
</div>
<div id="success"></div>
<!-- For success/fail messages -->
</div>
<div class="col-lg-12" data-aos="zoom-in">
<input type="submit" value="submit" class="btn btn-primary">
<a href="http://travel.melkbostravelandvisa.co.za/email_form.php"></a>
</div>
<div class="clearfix"></div>
</form>

</div>
</div>



===============================================

and the email_form.php file

<?php

if(isset($_POST['email'])) {



// EDIT THE 2 LINES BELOW AS REQUIRED

$email_to = "info@.co.za";

$email_subject = "New Enquiry";



function died($error) {

// your error code can go here

echo "We are very sorry, but there were error(s) found with the form you submitted. ";

echo "These errors appear below.<br /><br />";

echo $error."<br /><br />";

echo "Please go back and fix these errors.<br /><br />";

die();

}





// validation expected data exists

if(!isset($_POST['name']) ||

!isset($_POST['email']) ||

!isset($_POST['phone']) ||

!isset($_POST['message'])) {

died('We are sorry, but there appears to be a problem with the form you submitted.');

}







$first_name = $_POST['first_name']; // required

$email_from = $_POST['email']; // required

$telephone = $_POST['phone']; // not required

$comments = $_POST['message']; // required



$error_message = "";

$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';



if(!preg_match($email_exp,$email_from)) {

$error_message .= 'The Email Address you entered does not appear to be valid.<br />';

}



$string_exp = "/^[A-Za-z .'-]+$/";



if(!preg_match($string_exp,$first_name)) {

$error_message .= 'The First Name you entered does not appear to be valid.<br />';

}



if(!preg_match($string_exp,$last_name)) {

$error_message .= 'The Last Name you entered does not appear to be valid.<br />';

}



if(strlen($comments) < 2) {

$error_message .= 'The Comments you entered do not appear to be valid.<br />';

}



if(strlen($error_message) > 0) {

died($error_message);

}



$email_message = "Form details below.\n\n";





function clean_string($string) {

$bad = array("content-type","bcc:","to:","cc:","href");

return str_replace($bad,"",$string);

}







$email_message .= "Name: ".clean_string($first_name)."\n";

$email_message .= "Email: ".clean_string($email_from)."\n";

$email_message .= "phone: ".clean_string($telephone)."\n";

$email_message .= "message: ".clean_string($comments)."\n";



// create email headers

$headers = 'From: '.$email_from."\r\n".

'Reply-To: '.$email_from."\r\n" .

'X-Mailer: PHP/' . phpversion();

@mail($email_to, $email_subject, $email_message, $headers);

?>



<!-- include your own success html here -->



Thank you for contacting us. We will be in touch with you very soon.



<?php



}

?>


Attached File(s)
Attached File  email_form.php ( 2.66k ) Number of downloads: 149
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Feb 12 2018, 04:48 AM
Post #2


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



The action attribute is blank. Put the URL to the PHP file there and see if it works then.
QUOTE
CODE
<form action="" method="post" name="sentMessage" id="contactForm">
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 28th March 2024 - 10:09 AM