我的代码一直有问题。我在网站底部有一个简单的表格。如果我尝试填写并提交,它会返回代码或给我一个错误500(如果我尝试其他解决方案)。如果有帮助,我将托管在000webhost上。该网站的其余部分是在Bootstrap中创建的。
我对php相当了解,而且我根本不是Web开发人员,所以很抱歉如果我做的事情完全错误。
<?php
/*ini_set('display_errors', 1);*/
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$email_from = 'my_email';
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Name:\n $name"
"Email:\n $visitor_email"
"Subject:\n $subject"
"Message:\n $message".
$to = "my_email";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
?>
答案 0 :(得分:0)
缺少一些要点,也要用分号结束一行代码。
<?php
/*ini_set('display_errors', 1);*/
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$email_from = 'my_email';
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Name:\n $name".
"Email:\n $visitor_email".
"Subject:\n $subject".
"Message:\n $message";
$to = "my_email";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
?>