我对PHP编程非常不满意。我没有使用它的经验,但我希望在我的网站上有一个带有邮件脚本的表单。因此,几乎所有其他没有语言经验的人,我都会搜索并定制它。
mail_send.php
DocumentationCommentExteriorTrivia
EndOfLineTrivia
EndRegionDirectiveTrivia
MultiLineCommentTrivia
MultiLineDocumentationCommentTrivia
RegionDirectiveTrivia
SingleLineCommentTrivia
WhitespaceTrivia
这里是HTML代码:index.html
<?php
if(isset($_POST['submit'])){
$to = "my@mailadress.com"; // I just did this for privacy
$from = $_POST['email'];
$name = $_POST['name'];
$subject = "Form submission";
$message = $name . " " . $from . " wrote the following:" . "\n\n" .
$_POST['message'];
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
}
?>
所以我已将这两个文件上传到我的网站服务器,所以我已经在线测试了它,但仍然没有成功。任何聪明的家伙都能帮助我吗?
提前致谢:)
答案 0 :(得分:1)
答案 1 :(得分:0)
请修改按钮标记
<button type="submit" name="submit" id="feedbackSubmit" class="btn btn-primary btn-lg" style=" margin-top: 10px;"> Verstuur</button>
答案 2 :(得分:0)
在按钮标记中使用name = submit。
return
之后还检查您的垃圾邮件文件夹。有时你不会在收件箱中收到邮件。
答案 3 :(得分:0)
根据您的要求进行修改,我希望此代码能够直接向收件箱发送消息,而不是跨越
<?php
if(isset($_POST['submit'])){
$to = "Email Address Here"; // I just did this for privacy
$from = $_POST['email'];
$name = $_POST['name'];
$subject = "Form submission";
$message = $name." ".$from." wrote the following:". "\n\n". $_POST['message'];
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <info@example.com>' . "\r\n";
mail($to,$subject,$message,$headers);
echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Mail Example</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<form role="form" id="feedbackForm" class="text-center" action="" method="post">
<div class="form-group">
<label for="name">Naam</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Name">
<span class="help-block" style="display: none;">Voer uw naam in..</span></div>
<div class="form-group">
<label for="email">E-Mail</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Email Address">
<span class="help-block" style="display: none;">Voer een geldig e-mailadres in.</span></div>
<div class="form-group">
<label for="message">Bericht</label>
<textarea rows="10" cols="100" class="form-control" id="message" name="message" placeholder="Message"></textarea>
<span class="help-block" style="display: none;">Voer een bericht in.</span></div>
<button type="submit" name="submit" id="feedbackSubmit" class="btn btn-primary btn-lg" style=" margin-top: 10px;"> Verstuur</button>
</form>
</body>
</html>