有人可以帮忙解决这个问题吗,它总是说不明的索引和变量。是从文本字段获取数据的脚本?我正在尝试从网站发送电子邮件,但这一直在显示,无法发送电子邮件
<?php
$to ='jasoncas02@yahoo.com.ph';
$subject = 'Customer Inquiry';
$name = $_POST['name'];
$email = $_POST['email'];
$tel = $_POST['tel'];
$message = $_POST['message'];
$body = <<<EMAIL
Hi! My name is $name.
$message
from: $name
$email
$tel
EMAIL;
$header = "from:$email";
if($_POST){
if($name == ' ' || $email == ' ' || $message == ' '|| $tel == ' '){$feedback = 'Fill out all the fields';
}
else{
mail($to, $subject, $body, $header);
$feedback = "Thanks for you Email, We will answer your email as soon as possible";
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title></title>
<link rel="shortcut icon" href="pic/icon.png">
<meta charset="utf-8">
<!-- Google Fonts -->
<!-- CSS Files -->
<link rel="stylesheet" type="text/css" media="screen" href="style.css">
<link rel="stylesheet" type="text/css" media="screen" href="menu/css/simple_menu.css">
</head>
<body>
<div id="container">
<h1>Contact Us</h1>
<h2>Send Email</h2>
<p id="feedback"><?php echo $feedback; ?></p>
<form action="?" method="post">
<ul>
<li>
<label for=" name"><strong><font size="+2">Name:</font></strong></label>
<input name="name" id="name" type="text"><br><br>
</li>
<li>
<label for="tel"><strong><font size="+2">Telephone: </font></strong></label>
<input name="tel" id="telephone" type="text"><br><br>
</li>
<li>
<label for="email"><strong><font size="+2">Email: </font></strong></label>
<input name="email" id="email" type="email"><br><br>
</li>
<li>
<label for="message"><strong><font size="+2">Message: </font></strong></label>
<textarea rows="9" cols="42" name="message" id="message"></textarea><br>
</li>
<li>
<input value="Submit" type="submit">
</li>
</ul>
</form>
enter code here
</div>
</body>
</html>
答案 0 :(得分:0)
像这样制作$body
变量
$body = "
Hi! My name is ".$name."<br/>"
".$message."<br/>
from: ".$name."<br/>"
.$email."<br/>"
.$tel."<br/>"
";
答案 1 :(得分:0)
使用前检查$ _POST。
if(!empty($_POST) && isset($_POST['name']) && isset($_POST['tel']) && isset($_POST['email']) && isset($_POST['message'])){
//send mail code
}