我几年没有编写代码了,所以我要从一个超过5年的项目中删除旧代码,所以我并不感到惊讶它不起作用;我想要一些关于如何使它工作的指示。
以下是我在HTML电子邮件表单中的内容 -
<form action="fydcontact.php" method="post">
<div class="form-group">
<!--<label for="contact_name">Name:</label>-->
<input type="text" id="contact_name" class="form-control" placeholder="Name" />
</div>
<div class="form-group">
<!--<label for="contact_email">Email:</label>-->
<input type="text" id="contact_email" class="form-control" placeholder="Email Address" />
</div>
<div class="form-group">
<!--<label for="contact_message">Message:</label>-->
<textarea id="contact_message" class="form-control" rows="9" placeholder="Write a message"></textarea>
</div>
<button type="submit" class="btn btn-primary">Send</button>
</form>
这就是我的PHP的样子 -
<?php
if(isset($_POST['send'])) {
// Prepare the email
$to = ''foryourdayformals@gmail.com ';
$name = $_POST['contact_name'];
$mail_from = $_POST['contact_email'];
$subject = 'Message sent from website';
$message = $_POST['contact_message'];
$header = "From: $name <$mail_from>";
// Send it
$sent = mail($to, $subject, $message, $header);
if($sent) {
echo 'Your message has been sent successfully! <a href="http://www.foryourdayllc.com">Return to For Your Day, LLC Website</a>';
} else {
echo 'Sorry, your message could not send. Please use direct email link on Contact Us page (below the map). <a href="http://www.foryourdayllc.com">Return to For Your Day, LLC Website</a>';
}
}
?>
非常感谢任何帮助!谢谢!
答案 0 :(得分:0)
更新
$to = ''foryourdayformals@gmail.com ';
到
$to = 'foryourdayformals@gmail.com';
并需要为表单添加名称属性。这会更新您的表单
<form action="fydcontact.php" method="post">
<div class="form-group">
<!--<label for="contact_name">Name:</label>-->
<input type="text" id="contact_name" name="contact_name" class="form-control" placeholder="Name" />
</div>
<div class="form-group">
<!--<label for="contact_email">Email:</label>-->
<input type="text" id="contact_email" name="contact_email" class="form-control" placeholder="Email Address" />
</div>
<div class="form-group">
<!--<label for="contact_message">Message:</label>-->
<textarea id="contact_message" name="contact_message" class="form-control" rows="9" placeholder="Write a message"></textarea>
</div>
<button type="submit" class="btn btn-primary" name ="send">Send</button>
</form>