尝试将下拉菜单连接到我的联系页面时,我似乎无法找到错误。我已经关注了我的错误日志,但由于我对电子邮件不太熟悉,我的配置搞砸了,请提前感谢您的任何建议。
<?php
/***************** Configuration *****************/
// Enter your email, where you want to receive the messages.
$contact_email_to = "EMAIL NAME";
// Subject prefix
$contact_subject_prefix = " ";
// Name too short error text
$contact_error_name = "Name is too short or empty!";
// Email invalid error text
$contact_error_email = "Please enter a valid email!";
// Subject too short error text
$contact_error_subject = "Subject is too short or empty!";
// Message too short error text
$contact_error_message = "Too short message! Please enter something.";
if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
// The Request must be Ajax POST, enter a message for direct access requests.
die('Invalid Request!');
}
if( isset($_POST) ) {
$name = filter_var($_POST["name"], FILTER_SANITIZE_STRING);
$email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
$company = filter_var($_POST["company"], FILTER_SANITIZE_STRING);
$message = filter_var($_POST["message"], FILTER_SANITIZE_STRING);
$subject = ($_GET["subject"]);
if(strlen($name)<4){
die($contact_error_name);
}
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
die($contact_error_email);
}
if(strlen($company)<3){
die($contact_error_subject);
}
if(strlen($message)<3){
die($contact_error_message);
}
$sendemail = mail($contact_email_to, $company, $subject, $message,
"From: ".$name." <".$email.">" . PHP_EOL
."Reply-To: ".$email . PHP_EOL
."X-Mailer: PHP/" . phpversion()
);
if( $sendemail ) {
echo 'OK';
} else {
echo 'Could not send mail! Please check your PHP mail configuration.';
}
}
?>
<div class="row contact-wrap">
<div class="status alert alert-success" style="display: none"></div>
<div class="col-md-8">
<div id="sendmessage">Your message has been sent. Thank you!</div>
<div id="errormessage"></div>
<form action="" method="post" role="form" class="contactForm">
<div class="form-group">
<input type="text" name="name" class="form-control" id="name" placeholder="Your Name" data-rule="minlen:4" data-msg="Please enter at least 4 chars" />
<div class="validation"></div>
</div>
<div class="form-group">
<input type="email" class="form-control" name="email" id="email" placeholder="Your Email" data-rule="email" data-msg="Please enter a valid email" />
<div class="validation"></div>
</div>
<div class="form-group">
<input type="text" class="form-control" name="company" id="company" placeholder="Your Company" data-rule="minlen:4" data-msg="Please enter at least 4 chars" />
<div class="validation"></div>
</div>
<div class="form-group">
<select name="subject" class="form-control" name="subject" id="subject">
<option value="">---</option>
<option value="sales">Sales</option>
<option value="safety">Safety</option>
<option value="accountsP">Accounts Payable</option>
<option value="accountsR">Accounts Receivable</option>
<option value="accountsR">Human Resources</option>
<option value="accountsR">Operations</option>
<option value="accountsR">Equipment</option>
<option value="accountsR">Management</option>
</select>
</div>
<div class="form-group">
<textarea class="form-control" name="message" rows="5" data-rule="required" data-msg="Please write something for us" placeholder="Message"></textarea>
<div class="validation"></div>
</div>
<div class="text-center"><button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button></div>
</form>
</div>
&#13;
答案 0 :(得分:0)
据我解释,您无法获得subject
价值。问题是method
。您正在使用POST
方法提交表单并使用GET
来检索值。
$subject = ($_GET["subject"]);
应该是
$subject = ($_POST["subject"]);
如果您还无法发送电子邮件,则需要进行调试。有很多原因。我根据你的用例和我的理解列出了一些。