我将此PHP用于我的联系人表单,但它确实可以识别输入
有人能帮我解决我的问题吗我将此PHP用于我的联系人表单,但它确实可以识别输入,php,contact-form,Php,Contact Form,有人能帮我解决我的问题吗 谢谢,先给我看看你的HTML 确保已为表单设置了method=“post”。此外,检查输入的名称-它们必须匹配POST数组中的变量。您可以尝试将sprintf与$\u REQUEST一起使用,而不是$\u POST,因为$\u REQUEST将同时查看POST和get以及其他各种内容 From: E-mail: Phone: Priority: Type: Website: Message: 警报('谢谢您的消息。我们将很快与您联系'); window
谢谢,先给我看看你的HTML
确保已为表单设置了
method=“post”
。此外,检查输入的名称-它们必须匹配POST数组中的变量。您可以尝试将sprintf
与$\u REQUEST
一起使用,而不是$\u POST
,因为$\u REQUEST
将同时查看POST
和get
以及其他各种内容
From:
E-mail:
Phone:
Priority:
Type:
Website:
Message:
警报('谢谢您的消息。我们将很快与您联系');
window.location='contact_page.html';
警报(“消息失败,请重试”);
window.location='contact_page.html';
联系
请填写下表,我们会在24小时内给您回复。
姓名:(必填)
电子邮件:(必选)
电话:(必选)
你在找什么?(必选)
从这些中选择
选择1
选择2
选择3
类型:(必选)
个人的
小企业
专业的
网站:(必选)
信息:(必选)
发送电子邮件
请发布与此相关的HTML。我已经在Mike下面发布了HTML。谢谢,但现在可能有点晚了。在代码上我应该使用method=“REQUEST”吗?谢谢,但我现在唯一的问题是,@不是作为@发送的,而是%40?如何改变这一点?没有一种方法保持为post,我只是不确定您使用的“request”将在post和get中查找哪个方法。所以请把它们改成$邮政。如果用urldecode(“电子邮件”)包装电子邮件,它会将%40改为@符号。
From:
E-mail:
Phone:
Priority:
Type:
Website:
Message:
<?php
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$priority = $_REQUEST['priority'];
$type = $_REQUEST['type'];
$website = $_REQUEST['website'];
$message = $_REQUEST['message'];
$mail_to = 'info@mohdify.net';
$subject = sprintf("Message from a site visitor %s\n", $subject);
$body_message = sprintf("From: %s\n", $name);
$body_message .= sprintf("E-Mail: %s\n", $email);
$body_message .= sprintf("Phone: %s\n", $phone);
$body_message .= sprintf("Priority: %s\n", $priority);
$body_message .= sprintf("Type: %s\n", $type);
$body_message .= sprintf("Website: %s\n", $website);
$body_message .= sprintf("Message: %s\n", $message);
$headers = sprintf("From: %s\n", $email);
$headers .= sprintf("Reply-To: %s\n", $email);
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'contact_page.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please try ');
window.location = 'contact_page.html';
</script>
<?php
}
?>
<form id="contact-form" action="mail.php" method="POST">
<h3>Get in touch</h3>
<h4>Fill in the form below, and we'll get back to you within 24 hours.</h4>
<div>
<label>
<span>Name: (required)</span>
<input placeholder="Please enter your name" type="text" name="name" required autofocus>
</label>
</div>
<div>
<label>
<span>Email: (required)</span>
<input placeholder="Please enter your email address" type="email" name="email" tabindex="2" required>
</label>
</div>
<div>
<label>
<span>Telephone: (required)</span>
<input placeholder="Please enter your number" type="tel" name="phone" tabindex="3" required>
</label>
</div>
<div>
<label>
<span>What do you look for? (required)</span>
<select name="priority" size="1">
<option value="Low">Choose from these</option>
<option value="Normal">Option 1</option>
<option value="High">Option 2</option>
<option value="Emergency">Option 3</option>
</select> </label>
</div>
<div>
<label>
<span>Type: (required)</span>
<select name="type" size="1">
<option value="update">Personal</option>
<option value="change">Small Business</option>
<option value="addition">Professional</option>
</select>
</label>
</div>
<div>
<label>
<span>Website: (required)</span>
<input placeholder="Begin with http://" type="url"name="website" tabindex="4" >
</label>
</div>
<div>
<label>
<span>Message: (required)</span>
<textarea placeholder="Include all the details you can" tabindex="5" name="message" required></textarea>
</label>
</div>
<div>
<button name="submit" type="submit" id="contact-submit" value="send">Send Email</button>
</div>
</form>