[英]PHP contact form not working
I'm developing a kind of simple form for a side project I am doing. 我正在为正在做的辅助项目开发一种简单的表单。
It's based on a very simple contact form. 它基于一个非常简单的联系表。
I have a very similar one working here 我有一个非常相似的人在这里工作
https://crgdev.com/Contact/ https://crgdev.com/Contact/
But the one here doesn't appear to be working 但是这里的那个似乎没有用
https://crgdev.com/BrandAddition/ https://crgdev.com/BrandAddition/
Code below (very new to the site so probably doing something wrong) 下面的代码(对网站而言是全新的,所以可能做错了什么)
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "chris@crgdev.com";
$email_subject = "New Starter - ";
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();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['accessrequirements'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$accessrequirements = $_POST['accessrequirements']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($accessrequirements) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$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 .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Start Date: ".clean_string($start_date)."\n";
$email_message .= "Job Title: ".clean_string($job_title)."\n";
$email_message .= "Team Leader: ".clean_string($team_leader)."\n";
$email_message .= "Location: ".clean_string($location)."\n";
$email_message .= "Access Requirements: ".clean_string($accessrequirements)."\n";
$email_message .= "Email/Phone Access: ".clean_string($emailaccess)."\n";
$email_message .= "Other Requirements: ".clean_string($otherrequirements)."\n";
$email_message .= "Subitted by: ".clean_string($email_from)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for submitting your New STarter Form. We will be in touch with you regarding any updates.
<html>
<p>Go back to <a href="https://brandaddition.com">Brand Addition/a></p>
</html>
<style>
body {
font-size: larger;
text-align: center;
}
</style>
<?php
}
?>
<body>
<div class="fixedwidth">
<div id="brandlogo"><img src="brandadditionlogo.png"</div>
<h1>New Starter Form</h1>
<div id="formdiv">
<form name="newstarterform" method="post" action="send_form_email.php">
<table id="formtable">
<tr>
<td><input type="text" name="first_name" placeholder="First Name" maxlength="50"></td>
</tr>
<tr>
<td><input type="text" name="last_name" placeholder="Last Name" maxlength="50"></td>
</tr>
<tr>
<td>Start Date: <input type="date" name="start_date" placeholder="Start Date" maxlength="50"></td>
</tr>
<tr>
<td><input type="text" name="job_title" placeholder="Job Title" maxlength="50"></td>
</tr>
<tr>
<td><input type="text" name="team_leader" placeholder="Team Leader" maxlength="50"></td>
</tr>
<tr>
<td> Location:
<select name="location">
<option value="Manchester">Manchester</option>
<option value="London">London</option>
<option value="Ireland">Ireland</option>
</select>
</td>
</tr>
<tr>
<td>
<p class="pagepara"><span class="bold">List the access requirements needed, this should include</span><br><br>
• Level of oasis access or which user we should copy to set the oasis access level<br>
• Corporate programs that the user should have access to<br>
• Any specific applications that the employee would need access to<br>
• Which share drive folders should the employee have access to<br>
</p>
<textarea name="accessrequirements" placeholder="Access Requirements" maxlength="1000" cols="50" rows="10"></textarea>
</td>
</tr>
<tr>
<td>
<p class="pagepara"><span class="bold">List the email and telephone groups that the user should receive<br> communications from</span><br><br>
</p>
<textarea name="emailaccess" placeholder="Email/Phone Access" maxlength="1000" cols="50" rows="10"></textarea>
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="desktop computer">Desktop Computer
<input type="checkbox" name="laptop">Laptop <br>
<input type="checkbox" name="mobile phone">Mobile phone
<input type="checkbox" name="remote access">Remote Access<br><br>
<textarea name="otherrequirements" placeholder="Other requirements not mentioned above?" maxlength="1000" cols="50" rows="10"></textarea>
</td>
</tr>
<tr>
<td>
<p class="bold">Enter your email below for communications</p>
<input type="email" name="submitter">
</td>
</tr>
<tr>
<td style="padding: 40px 0px 80px 0px">
<input type="submit" value="Submit">
</td>
</tr>
</table>
</form>
</div>
<div id="blueline"></div>
</div>
</body>
I can't guarantee this is the only problem with your site. 我不能保证这是您网站的唯一问题。 However, I can guarantee this may solve a problem or two.
但是,我可以保证这可以解决一两个问题。
In your PHP code, you have an if
statement that determines if $_POST["email"];
在您的PHP代码中,有一个
if
语句,该语句确定$_POST["email"];
exists, right? 存在吧?
I went over your HTML document and found nothing in <form>
with the attribute name="email"
. 我遍历了您的HTML文档,并没有在
<form>
具有属性name="email"
。 How would that transfer over to your PHP document? 那将如何转移到您的PHP文档? It returns nothing because the page basically dies.
它什么也不会返回,因为该页面基本上已经死了。 I'm not sure about the "success HTML," but it may have something to do with the out of place end bracket for your
if
statement that I requested you to change. 我不确定“成功的HTML”是否正确,但是它可能与我要求您更改的
if
语句的不当结尾括号有关。
We can test this theory if you add an else
statement after the end of the if
statement, and also make sure that you're submitting an input or something with the name attribute set to "email." 如果添加的,我们可以验证这一理论
else
的结束后声明if
声明,并确保您要提交设置为名称属性的输入或某事“的电子邮件。”
**EDIT:**On your email textbox, your name
attribute is set to "submitter." **编辑:**在您的电子邮件文本框中,您的
name
属性设置为“ submitter”。 Change it to "email," then fix up your code so it will actually work. 将其更改为“电子邮件”,然后修正您的代码,使其可以正常工作。 This will at least give you some feedback.
这至少会给您一些反馈。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.