HTML5网站的Php联系表单部分无法正常工作

时间:2016-06-21 02:19:10

标签: php html css server filezilla

我目前有我的网站www.vivascoaching.com,我似乎无法收到该页面的联系表单部分,以便在我填写的表单填写时给我发回电子邮件。目前我有一个index.html文件和一个名为callback.php的独立php文件。我是php的新手,所以我不确定这是否是正确的方法。

这是index.html文件:

this.props.params.userId

这就是callback.php:

...+plane_ride_cost(days)

1 个答案:

答案 0 :(得分:1)

EDITED

我编辑了你的代码。输入不正确。我的意思是你可以使用 电子邮件<input type="email" name="email" placeholder="email" />。 (该输入将需要@domain。) 此外,您可以使用必需的。类似于<input type="text" name="test" required />

我已经编辑了你的回调。使用它。

检查编辑3

我摆脱了isset($ _ POST ['submit']),这很头疼!

编辑2:

永远不要为php中的数字使用引号('")。那不需要。

编辑3(希望最后一个。)

如果要在索引上显示消息,我会使用标头重定向GET请求。

例如:index.php

<!doctype html>
<html>
<head>
</head>
<body>
<?php
error_reporting(0) // prevent undefined index.
if(isset($_GET['success']) && $_GET['success']) {
echo "<p>Your message has been sent!</p>";
} elseif(isset($_GET['error']) && $_GET['error'] && isset($_GET['message'])) {
echo $_GET['message']; // Print message like ?error=true&message=test.
//  echo '<p>'.$_GET['message'].'</p>'; if you don't know how to add html before it.
}
?>
</body>
</html>

(索引需要是.php)!

callback.php将是:

<?php
if(isset($_POST['human']) && isset($_POST['email'])) {  
   $firstname = $_POST['firstname'];  
   $lastname = $_POST['lastname']; 
   $email = $_POST['email']; 
   $message = $_POST['message'];
   $to = 'vivascoaching@gmail.com';
   $subject = 'inquiry';
   $human = $_POST['human'];


   $body ="From: $firstname\n $lastname\n Email: $email\n Message:\n $message";


   if ($human == 4) {                
        if (mail ($to, $subject, $body)) { 
        header('location:index.php?success=true');
    } else { 
        header('location:index.php?error=true&message=Something went wrong, go back and try again!');
    } 
    } else if ($human != 4) {
        header('location:index.php?error=true&message=You answered the anti-spam question incorrectly!');
    }  
} else { header('location:index.php?error=true&message=Form is incomplete.'); }
?>