PHP联系人表单脚本将无法运行/页面将会打开 [英] PHP contact form script won't run/ page opens instead

查看:104
本文介绍了PHP联系人表单脚本将无法运行/页面将会打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我陷入困境,希望有人能帮助我。我正在尝试使用PHP action = method = post向我的网站添加一个简单的联系表。当我单击提交按钮而不是运行脚本时,将打开 send_contact.php页面,您会看到所有代码。我已经检查并测试了我的服务器(blue.host),并将其设置为运行php脚本。我已经尝试了一切,但很茫然。以下是HTML:

I'm stuck and I hope someone can help me. I'm trying to add a simple contact form to my website using PHP action=" " method="post". When I click the "submit" button, instead of running the script, the "send_contact.php" page opens and you see all the code. I've checked and tested my server (blue.host) and it is set up to run php scripts. I've tried everything and I'm at a loss. Here is the HTML:

<div class="form">
<form id="myform" name="myform" action="send_contact.php" method="post">
<label>Name</label>

<input type="text" name="name" id="name" />                 
<label>E-mail</label>
<input type="text" name="email" id="email" />

<label>Phone</label>
<input type="text" name="phone" id="phone" />

<label>Message</label>
<textarea name="message" rows="5" cols="60"></textarea>

<button name="send" type="submit">send</button>
<button name="reset" type="reset">reset</button>
<div class="spacer"></div>
</form><!--end myform div-->
</div><!--end form div-->                       

以下是PHP脚本:

<?php

// From
$header="from: $name <$mail_from>";

// Mail of sender
$mail_from="$customer_mail";

// Contact phone
$phone ="$phone"; 

// Details
$message="$message";


// Enter your email address
$to ='jacine.arias@gmail.com';

$send_contact=mail($to,$header,$mail,$phone,$message);


// Check, if message sent to your email
// display message "Thank you! Your message has been recieved."
if($send_contact){
echo "Thank you! Your message has been recieved.";
}
else {
echo "ERROR";
}
?>

以下是CSS:

/*-----------FORM---------------*/

.form {
    border: 1px solid #262223;
    margin: 0 auto;
    padding: 14px;
    width: 375px;

}

.form label {
    display: block;
    text-align: right;
    width: 80px;
    float: left;
}

.form input {
    float: left;
    font-size: 12px;
    padding: 4px 2px;
    border: 1px solid #262223;
    width: 270px;
    margin: 2px 0 10px 10px;
}

textarea {
    float: left;
    font-size: 12px;
    padding: 4px 2px;
    border: 1px solid #262223;
    width: 270px;
    margin: 2px 0 20px 10px;
}

button[type="submit"] {
    clear: both;
    color: #fff;
    width: 100px;
    height: 31px;
    text-align: center;
    background: #F20F4B;
    margin-right: 5px;
    float: left;
}

button[type="reset"] {
    clear: both;
    color: #fff;
    width: 100px;
    height: 31px;
    text-align: center;
    background: #F20F4B;
    display: inline;
}

这是我网站上的实际页面: http://jacineariasdesign.jacineariasweb.com/contact.html
对此工作的任何帮助将不胜感激!
谢谢!

Here the actual page from my website:http://jacineariasdesign.jacineariasweb.com/contact.html Any help to make this work would be appreciated! Thank you!

推荐答案

在这里,尝试一下。经过测试,可以承受要通过额外的安全功能进行修改,但它可以与您提供的表单一起使用。

Here, give this a try. Tested and could stand to be modified with extra security features, but it works with your form supplied.

还添加了一些错误检查。

Added a bit of error checking also.

如果它不适合您,则说明您的服务器上存在PHP问题。

您原始的PHP脚本开头没有 Subject 条目。

Your original PHP script never had a Subject entry to start with.

<?php

$headersep = "\r\n";
$header = "From: $name <$email>" . $headersep . "Reply-To: $name <$email> . $headersep";
$email = $_POST['email'];
$subject="Your subject here";
$phone = $_POST['phone']; 
$message = "From: $name\n\nMessage: $message\n\nEmail: $email\n\nTelephone: $phone";
$to ='youremail@example.com';

if (!empty ($_POST['email']) && ($_POST['message'])) {
  mail($to, $subject, $message, $header);
echo "Thank you $name, your message has been received.";
exit;
}

if ( (empty ($_POST['email'])) && (empty ($_POST['message'])) ) {
echo "ERROR, you did not fill in the <b>Email</b> and the <b>message</b> body.";
exit;
}

elseif (empty ($_POST['email'])) {
echo "ERROR, you did not fill in your Email address.";
exit;
}

elseif (empty ($_POST['message'])) {
echo "ERROR, you did not fill in the message body.";
exit;
}

?>

这篇关于PHP联系人表单脚本将无法运行/页面将会打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆