我正在尝试制作一个将发送到我的电子邮件的表格。但它在提交时显示错误。未显示用于验证表单的 Javascript,但它工作正常。我不确定下面的代码有什么问题,整天都在试图弄清楚并阅读各种线程但无济于事。
下面是我处理表单的 php 代码。
<?php
if(isset($_POST['name'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "me@gmail.com";
$email_subject = "Nexwave Form";
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();
}
$name = $_POST['name']; // required
$designation = $_POST['designation'];
$company = $_POST['company'];
$contact = $_POST['contact'];
$email = $_POST['email']; // not required
$users = $_POST['users']; // required
$error_message = "";
$string_exp = "/^[A-Za-z .'-]+$/";
$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($name)."\n";
$email_message .= "Designation: ".clean_string($designation)."\n";
$email_message .= "company: ".clean_string($company)."\n";
$email_message .= "Contact ".clean_string($contact)."\n";
$email_message .= "email: ".clean_string($email)."\n";
$email_message .= "Number of Users: ".clean_string($users)."\n";
// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
echo (int) 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
}
?>
下面是我的html代码:
<form name="form" action="send_mail.php" onSubmit="return validateForm();" method="POST">
Name<br/><input name="name" type="text" style="width:90%;"/><br/>
Designation<br/><input name="designation" type="text" style="width:90%;"/><br/>
Company<br/><input name="company" type="text" style="width:90%;"/><br/>
Contact Number<br/><input name="contact" type="text" style="width:90%;"/><br/>
Email<br/><input name="email" type="text" style="width:90%;"/><br/>
Number of Users<br/><input name="users" type="text" style="width:90%;"/>
<span style="text-align:right;display:block;width:174px;"><input style="height:25px;margin-top:20px;margin-bottom:10px;background-color:#ffffff;border:0;color:#009110;" type="submit" class="submit" value="Submit" /></span>
</form>
以下是错误:即使在更改 email_address 和 email_from 后,我也会得到。
"; echo $error."
"; echo "Please go back and fix these errors.
"; die(); } $name = $_POST['name']; // required $designation = $_POST['designation']; $company = $_POST['company']; $contact = $_POST['contact']; $email = $_POST['email']; // not required $users = $_POST['users']; // required $error_message = ""; $string_exp = "/^[A-Za-z .'-]+$/"; $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($name)."\n"; $email_message .= "Designation: ".clean_string($designation)."\n"; $email_message .= "company: ".clean_string($company)."\n"; $email_message .= "Contact ".clean_string($contact)."\n"; $email_message .= "email: ".clean_string($email)."\n"; $email_message .= "Number of Users: ".clean_string($users)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email."\r\n" . 'X-Mailer: PHP/' . phpversion(); echo (int) mail($email_to, $email_subject, $email_message, $headers); ?> Thank you for contacting us. We will be in touch with you very soon.
非常感激你的帮助