我有一个html输入表单以及一个php电子邮件脚本,它可以在同一页面上使用这些值。PHP:在执行脚本之前等待用户输入
问题是,在我向表单提交任何数据之前,我收到一封空白电子邮件,因为我的php脚本没有等待用户输入。
我不想为我的电子邮件脚本使用另一个页面,因为我不想通过GET传递变量,我也不知道如何实现会话。
由于这里是我的代码
if (!isset($_POST['submit'])) {
echo 'you have hit the submit button';
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$email_from = '[email protected]';
$email_subject = "Message from client";
$email_body = "Message from: $visitor_email \n \n Message:$message";
$to = "[email protected]";
$headers = "from:adam\r\n";
mail($to,$email_subject,$email_body,$headers);
} else {
echo 'You have not hit the submit button yet';
}
?>
+0
PHP脚本没有 '等待' 输入......他们跑。运行另一个脚本。这并不意味着任何会话的方式......其他脚本可以捕捉您的表单以及第一个。这里有一些阅读可能会使你不关心服务器和客户端:http://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming –
2014-10-20 19:54:46