Код контактной формы ниже дает мне ошибку, FORM SENDING FAILED
.
Не могли бы вы помочь мне решить проблему? Код контактной формы ниже дает мне сообщение об ошибке " FORM SENDING FAILED
.
Не могли бы вы помочь мне решить проблему? Код контактной формы ниже дает мне сообщение об ошибке " FORM SENDING FAILED
.
Не могли бы вы помочь мне решить проблему?
<form id="contactform" method="post" action="$_SELF">
<label class="hide" for="author">Full Name</label>
<input class="input-fields" id="author" name="name" type="text" placeholder="Full Name" value="" required autofocus />
<label class="hide" for="email">Email</label>
<input class="input-fields" id="email" name="email" type="text" placeholder="Email Address" value="" autofocus />
<label class="hide" for="email">Mobile No</label>
<input class="input-fields" id="email" name="phone_no" type="text" placeholder="Mobile No" value="" autofocus />
<label class="hide" for="author">Company</label>
<input class="input-fields" id="author" name="company" type="text" placeholder="Company" value="" required autofocus />
<label class="hide" for="select_category">Select a Industry:</label>
<span id="select_group" class="select-group">
<select name="vehicle">
<option value="General" >Select a Industry:</option>
<option value="General" >Health Centres Hospitals</option>
<option value="Sales" >Tradeshows Conferences</option>
<option value="Support" >Fast Foods and Restaurants</option>
<option value="Support" >Night CLub, Bars and Disos</option>
<option value="Support" >Banks , Rent Estate</option>
<option value="Support" >Educational Institute</option>
<option value="Support" >Recreational Facilities</option>
<option value="Support" >Malls,Luxury Retail and Store Windows</option>
</select>
</span>
<label class="hide" for="subject_title">Solutions</label>
<input class="input-fields" id="subject_title" name="solution" type="text" placeholder="Solutions" value="" autofocus />
<label class="hide" for="author">Require</label>
<input class="input-fields" id="author" name="require" type="text" placeholder="Require" value="" required autofocus />
<label class="hide" for="comment">Message</label>
<textarea id="comment" class="input-fields" placeholder="Message" name="message" cols="40" rows="200"></textarea>
<span class="form_response">
<ul id="errors" class="">
<li id="info">There were some problems with your form submission:</li>
</ul>
<p id="success" class="">Thanks for your message! We will get back to you ASAP!</p>
</span>
<input name="submit" type="submit" id="submit-contact-info" class="contact-info-submit form-submit-button span2" value="Send message">
</form>
</div>
</div>
</article>
</main>
</div>
<?php
//If the form is submitted
echo "hello";
if(isset($_REQUEST['submit']))
{
$message = $_POST['message'];
}
//Check to make sure that the exit date field is not empty
if(trim($_POST['vehicle']) == '') {
$hasError = true;
} else {
$vehicle = trim($_POST['vehicle']);
}
//Check to make sure that the exit date field is not empty
if(trim($_POST['require']) == '') {
$hasError = true;
} else {
$require = trim($_POST['require']);
}
//Check to make sure that the exit date field is not empty
if(trim($_POST['solution']) == '') {
$hasError = true;
} else {
$solution = trim($_POST['solution']);
}
//Check to make sure that the name field is not empty
if(trim($_POST['name']) == '') {
$hasError = true;
} else {
$name = trim($_POST['name']);
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
$hasError = true;
} else {
$email = trim($_POST['email']);
}
//Check to make sure that the mobile no field is not empty
if(trim($_POST['phone_no']) == '') {
$hasError = true;
} else {
$phone_no = trim($_POST['phone_no']);
}
//If there is no error, send the email
if(!isset($hasError))
{
$emailTo = "[email protected]"; //Put your own email address here
$body = "Name: $name \n\nEmail: $email \n\nMobile No: $phone_no \n\n Your Industry: $vehicle \n\
\n\n Your Requirement: $require \n\n Your Solution: $solution \n\n
\n\n Message : $message
\n\nPlease Contact $name on $phone_no\n \n /====================================/ ";
$headers = 'From: Touch Active <'. $emailTo .'>' . "\r\n" . 'Reply-To: ' . $email;
if(mail($emailTo, 'Mail From Touch Active', $body, $headers))
{ //Replace Your Website Subject
$response=1;
$emailSent = true;
?>
<div id="responsive-container" ><p>Thanks For Messaging Us You Will Shortly Expect Our Assistance ( With In 24hrs ).</p></div>
<?php
}
else
{
?>
<div id="page-title"><h2>Failed To Sent</h2></div>
<?php
$response=0;
}
}
?>
Изменить форму action="$_SELF"
на action="$_SERVER['PHP_SELF']"
, потому что не существует константы, как $_SELF
.
На самом деле его работа здесь без ошибок, попробуйте с этим маленьким скриптом, проверить или отправить по электронной почте:
<?php
$to = "[email protected]";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: [email protected]" . "\r\n" .
"CC: [email protected]";
mail($to,$subject,$txt,$headers);
?>
Я проверил ваш скрипт с небольшой настройкой:
<form id="contactform" method="post" action="#">
<label class="hide" for="author">Full Name</label>
<input class="input-fields" id="author" name="name" type="text" placeholder="Full Name" value="aaa" required autofocus />
<label class="hide" for="email">Email</label>
<input class="input-fields" id="email" name="email" type="text" placeholder="Email Address" value="[email protected]" autofocus />
<label class="hide" for="email">Mobile No</label>
<input class="input-fields" id="email" name="phone_no" type="text" placeholder="Mobile No" value="0322233355" autofocus />
<label class="hide" for="author">Company</label>
<input class="input-fields" id="author" name="company" type="text" placeholder="Company" value="aaa" required autofocus />
<label class="hide" for="select_category">Select a Industry:</label>
<span id="select_group" class="select-group">
<select name="vehicle">
<option value="General" >Select a Industry:</option>
<option value="General" >Health Centres Hospitals</option>
<option value="Sales" >Tradeshows Conferences</option>
<option value="Support" >Fast Foods and Restaurants</option>
<option value="Support" >Night CLub, Bars and Disos</option>
<option value="Support" >Banks , Rent Estate</option>
<option value="Support" >Educational Institute</option>
<option value="Support" >Recreational Facilities</option>
<option value="Support" >Malls,Luxury Retail and Store Windows</option>
</select>
</span>
<label class="hide" for="subject_title">Solutions</label>
<input class="input-fields" id="subject_title" name="solution" type="text" placeholder="Solutions" value="aaa" autofocus />
<label class="hide" for="author">Require</label>
<input class="input-fields" id="author" name="require" type="text" placeholder="Require" value="aaa" required autofocus />
<label class="hide" for="comment">Message</label>
<textarea id="comment" class="input-fields" placeholder="Message" name="message" cols="40" rows="20"></textarea>
<span class="form_response">
<ul id="errors" class="">
<li id="info">There were some problems with your form submission:</li>
</ul>
<p id="success" class="">Thanks for your message! We will get back to you ASAP!</p>
</span>
<input name="submit" type="submit" id="submit-contact-info" class="contact-info-submit form-submit-button span2" value="Send message">
</form>
</div>
</div>
</article>
</main>
</div>
<?php
//If the form is submitted
if(isset($_REQUEST['submit']))
{
$message = $_POST['message'];
}
//Check to make sure that the exit date field is not empty
if(trim($_POST['vehicle']) == '') {
$hasError = "1";
} else {
$vehicle = trim($_POST['vehicle']);
}
//Check to make sure that the exit date field is not empty
if(trim($_POST['require']) == '') {
$hasError = "2";
} else {
$require = trim($_POST['require']);
}
//Check to make sure that the exit date field is not empty
if(trim($_POST['solution']) == '') {
$hasError = "3";
} else {
$solution = trim($_POST['solution']);
}
//Check to make sure that the name field is not empty
if(trim($_POST['name']) == '') {
$hasError = "4";
} else {
$name = trim($_POST['name']);
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$hasError = "5";
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
$hasError = "6";
} else {
$email = trim($_POST['email']);
}
//Check to make sure that the mobile no field is not empty
if(trim($_POST['phone_no']) == '') {
$hasError = "7";
} else {
$phone_no = trim($_POST['phone_no']);
}
//If there is no error, send the email
if(!isset($hasError))
{
echo "OK";
$emailTo = "[email protected]"; //Put your own email address here
$body = "Name: $name \n\nEmail: $email \n\nMobile No: $phone_no \n\n Your Industry: $vehicle \n\
\n\n Your Requirement: $require \n\n Your Solution: $solution \n\n
\n\n Message : $message
\n\nPlease Contact $name on $phone_no\n \n /====================================/ ";
$headers = 'From: Touch Active <'. $emailTo .'>' . "\r\n" . 'Reply-To: ' . $email;
if(mail($emailTo, 'Mail From Touch Active', $body, $headers))
{ //Replace Your Website Subject
$response=1;
$emailSent = true;
?>
<div id="responsive-container" ><p>Thanks For Messaging Us You Will Shortly Expect Our Assistance ( With In 24hrs ).</p></div>
<?php
}
else
{
?>
<div id="page-title"><h2>Failed To Sent</h2></div>
<?php echo "NOK";
echo $hasError;
echo $response;
$response=0;
}
}
else{
echo $hasError;
}
?>
Failed To Sent
или неFailed To Sent
FORM SENDING FAILED
? Потому что, кажется, вы могли бы получить первый, и в своем вопросе вы сказали, что это был второй. Что это?$sent = mail($emailTo, 'Mail From Touch Active', $body, $headers ) { //Replace Your Website Subject