我在为网站创建联系表单后遇到的问题上谦卑地寻求帮助。点击提交后,我得到的只是一个"错误!"信息。我相信这个问题与我使用的php脚本有关。验证脚本虽然运行良好。我将粘贴php脚本并在此处形成html,以便您可以帮助调查它。非常感谢您的帮助!提前谢谢!
<?php
$owner_email='name@domain.com';
//SMTP server settings
$host = '';
$port = '465';//"587";
$username = '';
$password = '';
$subject='A message from your site visitor ';
$user_email='';
$message_body='';
$message_type='html';
$max_file_size=50;//MB
$file_types='/(doc|docx|txt|pdf|zip|rar)$/';
$error_text='something goes wrong';
$error_text_filesize='File size must be less than';
$error_text_filetype='Failed to upload file. This file type is not allowed. Accepted files types: doc, docx, txt, pdf, zip, rar.';
$private_recaptcha_key='6LeZwukSAAAAACmqrbLmdpvdhC68NLB1c9EA5vzU'; //localhost
$use_recaptcha=isset( $_POST["recaptcha_challenge_field"]) and isset($_POST["recaptcha_response_field"]);
$use_smtp=($host=='' or $username=='' or $password=='');
$max_file_size*=1048576;
if($owner_email==''){
die('Attention, recipient e-mail is not set! Please define "owner_email" variable in the MailHanlder.php file.');
}
if(preg_match('/^(127\.|192\.168\.)/',$_SERVER['REMOTE_ADDR'])){
die('Attention, contact form will not work locally! Please upload your template to a live hosting server.');
}
if($use_recaptcha){
require_once('recaptchalib.php');
$resp = recaptcha_check_answer ($private_recaptcha_key,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"],$_POST["recaptcha_response_field"]);
if (!$resp->is_valid){
die ('wrong captcha');
}
}
if(isset($_POST['name']) and $_POST['name'] != ''){$message_body .= '<p>Visitor: ' . $_POST['name'] . '</p>' . "\n" . '<br>' . "\n"; $subject.=$_POST['name'];}
if(isset($_POST['title']) and $_POST['title'] != ''){$message_body .= '<p>Course Title: ' . $_POST['title'] . '</p>' . "\n" . '<br>' . "\n";}
if(isset($_POST['organisation']) and $_POST['organisation'] != ''){$message_body .= '<p>Organisation: ' . $_POST['organisation'] . '</p>' . "\n" . '<br>' . "\n";}
if(isset($_POST['work']) and $_POST['work'] != ''){$message_body .= '<p>Work Description: ' . $_POST['work'] . '</p>' . "\n" . '<br>' . "\n";}
if(isset($_POST['address']) and $_POST['address'] != ''){$message_body .= '<p>Address: ' . $_POST['address'] . '</p>' . "\n" . '<br>' . "\n";}
if(isset($_POST['city']) and $_POST['city'] != ''){$message_body .= '<p>City: ' . $_POST['city'] . '</p>' . "\n" . '<br>' . "\n";}
if(isset($_POST['states']) and $_POST['states'] != ''){$message_body .= '<p>State: ' . $_POST['states'] . '</p>' . "\n" . '<br>' . "\n";}
if(isset($_POST['email']) and $_POST['email'] != ''){$message_body .= '<p>Email Address: ' . $_POST['email'] . '</p>' . "\n" . '<br>' . "\n"; $user_email=$_POST['email'];}
if(isset($_POST['phone']) and $_POST['phone'] != ''){$message_body .= '<p>Phone Number: ' . $_POST['phone'] . '</p>' . "\n" . '<br>' . "\n";}
if(isset($_POST['fax']) and $_POST['fax'] != ''){$message_body .= '<p>Fax Number: ' . $_POST['fax'] . '</p>' . "\n" . '<br>' . "\n";}
if(isset($_POST['enquiry']) and $_POST['enquiry'] != ''){$message_body .= '<p>Any Enquiry?: ' . $_POST['enquiry'] . '</p>' . "\n" . '<br>' . "\n";}
if(isset($_POST['message']) and $_POST['message'] != ''){$message_body .= '<p>Message: ' . $_POST['message'] . '</p>' . "\n";}
if(isset($_POST['stripHTML']) and $_POST['stripHTML']=='true'){$message_body = strip_tags($message_body);$message_type='text';}
try{
include "libmail.php";
$m= new Mail("utf-8");
$m->From($user_email);
$m->To($owner_email);
$m->Subject($subject);
$m->Body($message_body,$message_type);
//$m->log_on(true);
if(isset($_FILES['attachment'])){
if($_FILES['attachment']['size']>$max_file_size){
$error_text=$error_text_filesize . ' ' . $max_file_size . 'bytes';
die($error_text);
}else{
if(preg_match($file_types,$_FILES['attachment']['name'])){
$m->Attach($_FILES['attachment']['tmp_name'],$_FILES['attachment']['name'],'','attachment');
}else{
$error_text=$error_text_filetype;
die($error_text);
}
}
}
if(!$use_smtp){
$m->smtp_on( $host, $username, $password, $port);
}
if($m->Send()){
die('success');
}
}catch(Exception $mail){
die($mail);
}
?>
HTML-----
<form id="contact-form" action='MailHandler.php'>
<div class="contact-form-loader"></div>
<fieldset>
<div class="row">
<div class="grid_2">
<label class="name">
<input type="text" name="name" placeholder="Name:" value=""
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>
</div>
<div class="grid_2">
<label class="email">
<input type="text" name="email" placeholder="E-mail:" value=""
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>
</div>
<div class="grid_2">
<label class="phone">
<input type="text" name="phone" placeholder="Phone:" value=""
data-constraints="@JustNumbers"/>
<span class="empty-message">*This field is required.</span>
<span class="error-message">*This is not a valid phone.</span>
</label>
</div>
</div>
<label class="message">
<textarea name="message" placeholder="Message:"
data-constraints='@Required @Length(min=20,max=999999)'></textarea>
<span class="empty-message">*This field is required.</span>
<span class="error-message">*The message is too short.</span>
</label>
<div class="btn-wrap">
<a class="btn_3" href="#" data-type="reset">clear</a>
<a class="btn_3" href="#" data-type="submit">send</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">×</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>