【发布时间】:2019-12-06 01:41:11
【问题描述】:
当使用 html 表单调用 php 将包含表单中详细信息的电子邮件发送到 php.ini 中指定的电子邮件地址时。 php 文件名添加到 URL,但没有发送电子邮件,页面显示为空白。
该网站使用 php 7.3 托管在 my.ionos.co.uk (1&1) 上。
<form method="post" action="contact-form.php">
<input class="contact" type="text" name="Name" placeholder="Name">
<input class="contact" type="text" name="Email" placeholder="Your Email Address">
<input class="contact" type="text" name="Subject" placeholder="Subject">
<textarea class="contact" name="Message" rows="10" placeholder="Message"></textarea>
<input class="contact-submit" type="submit" value="Send Message">
</form>
<?php
if(isset($_POST['submit'])) {
$name = $_POST['Name'];
$mailFrom = $_POST['Email'];
$subject = $_POST['Subject'];
$message = $_POST['Message'];
$mailTo = "X@hotmail.com";
$headers = "From: ".$mailFrom;
$txt = "You have recieved an email from ".$name.".\n\n".$Message;
if(mail($mailTo, $subject, $txt, $headers)){
echo "<h1>Mail send successfully</h1>";
} else {
echo "<h1>Mail failed to send<h1>";
}
header("Location: contact.html?mailsend");
}
?>
如果有人可以提供帮助,我将不胜感激,在此先感谢!
【问题讨论】:
-
在
contact-form.php中尝试添加var_dump($_POST);。$_POSTvar 可以吗?