<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: yoursite.com';
$to = '[email protected]';
$subject = 'Customer Inquiry';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
}
?>
我尝试创建一个简单的邮件表单。表单本身在我的 index.html
页面上,但它提交到一个单独的“感谢您的提交”页面, thankyou.php
上面的 PHP 代码嵌入其中。代码提交完美,但从未发送电子邮件。我该如何解决这个问题?
我在 000webhost 上通过执行以下操作来使用它:
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: ". $from. "\r\n";
$headers .= "Reply-To: ". $from. "\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();
$headers .= "X-Priority: 1" . "\r\n";
发送邮件时直接输入邮箱地址:
mail('[email protected]', $subject, $message, $headers)
使用 ''
而不是 ""
.
该代码有效,但电子邮件接收延迟了半小时。