大家好,这是我在这个模板中购买的模板,有一个现成的PHP表单用于发送和发送电子邮件,但它没有工作,任何人都可以帮助请。 我尝试了很多方式,顺便说一句,我在PHP中没那么好,但我需要使用这个php联系人
contact.html
<div class="contact-main">
<div class="container">
<div class="row">
<div class="col-lg-12 col-12">
<div class="box-contact-right-form">
<h3>Get In Touch</h3>
<form id="contact-form-cont" class="contact-right-form" method="post" action="contact.php">
<div class="row clearfix">
<div class="form-group col-md-12">
<input name="name" id="name-cont" value="" placeholder="Your Name" required="" type="text">
</div>
<div class="form-group col-md-12">
<input name="mail" id="mail-cont" value="" placeholder="Email Address" required="" type="email">
</div>
<div class="form-group col-md-12">
<input name="number" id="number-cont" value="" placeholder="Phone Number" required="" type="text">
</div>
<div class="form-group col-md-12">
<input id="company-cont" name="company" value="" placeholder="Company" required="" type="text">
</div>
<div class="form-group col-md-12">
<textarea name="comment" id="comment-cont" placeholder="Message"></textarea>
</div>
<div class="form-group col-md-12">
<button id="submit_contact-cont" type="submit" name="submit" class="theme-btn btn-style-one button-wayra-a">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
这个联系人我检查了很多,但我没有看到任何错误,顺便说一句,我没有那么好的PHP
contact.php
<?php
/* ========================== Define variables ========================== */
#Your e-mail address
define("__TO__", "xxxxxxxxxxxxxxxxx@gmail.com= From:");
#Message subject
define("__SUBJECT__", "xxxxxxxxxxxxxxxxx@gmail.com= From:");
#Success message
define('__SUCCESS_MESSAGE__', "Your message has been sent. Thank you!");
#Error message
define('__ERROR_MESSAGE__', "Error, your message hasn't been sent");
#Messege when one or more fields are empty
define('__MESSAGE_EMPTY_FILDS__', "Please fill out all fields");
/* ======================== End Define variables ======================== */
//Send mail function
function send_mail($to,$subject,$message,$headers){
if(@mail($to,$subject,$message,$headers)){
echo json_encode(array('info' => 'success', 'msg' => __SUCCESS_MESSAGE__));
} else {
echo json_encode(array('info' => 'error', 'msg' => __ERROR_MESSAGE__));
}
}
//Check e-mail validation
function check_email($email){
if(!@eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
return false;
} else {
return true;
}
}
//Get post data
if(isset($_POST['name']) and isset($_POST['mail']) and isset($_POST['comment'])){
$name = $_POST['name'];
$mail = $_POST['mail'];
$number = $_POST['number'];
$company = $_POST['company'];
$comment = $_POST['comment'];
if($name == '') {
echo json_encode(array('info' => 'error', 'msg' => "Please enter your Name."));
exit();
} else if($mail == '' or check_email($mail) == false){
echo json_encode(array('info' => 'error', 'msg' => "Please enter valid E-mail."));
exit();
} else if($number == ''){
echo json_encode(array('info' => 'error', 'msg' => "Please enter your Number."));
exit();
} else if($company == ''){
echo json_encode(array('info' => 'error', 'msg' => "Please enter your Company."));
exit();
} else if($comment == ''){
echo json_encode(array('info' => 'error', 'msg' => "Please enter your Message."));
exit();
} else {
//Send Mail
$to = __TO__;
$subject = __SUBJECT__ . ' ' . $name;
$message = '
<html>
<head>
<title>Mail from '. $name .'</title>
</head>
<body>
<table style="width: 500px; font-family: arial; font-size: 14px;" border="1">
<tr style="height: 32px;">
<th align="right" style="width:150px; padding-right:5px;">Name:</th>
<td align="left" style="padding-left:5px; line-height: 20px;">'. $name .'</td>
</tr>
<tr style="height: 32px;">
<th align="right" style="width:150px; padding-right:5px;">E-mail:</th>
<td align="left" style="padding-left:5px; line-height: 20px;">'. $mail .'</td>
</tr>
<tr style="height: 32px;">
<th align="right" style="width:150px; padding-right:5px;">Website:</th>
<td align="left" style="padding-left:5px; line-height: 20px;">'. $website .'</td>
</tr>
<tr style="height: 32px;">
<th align="right" style="width:150px; padding-right:5px;">Comment:</th>
<td align="left" style="padding-left:5px; line-height: 20px;">'. $comment .'</td>
</tr>
</table>
</body>
</html>
';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: ' . $mail . "\r\n";
send_mail($to,$subject,$message,$headers);
}
} else {
echo json_encode(array('info' => 'error', 'msg' => __MESSAGE_EMPTY_FILDS__));
}
?>
答案 0 :(得分:0)
尝试将常量更改为:
#Your e-mail address
define("__TO__", "youraddress@gmail.com");
#Message subject
define("__SUBJECT__", "This is the subject");