我最近了解到我没有从我的页面联系表单中收到电子邮件。它以前总是奏效。所以我一直在尝试不同的脚本,包括PHPEmailer和没有雪茄。我在这里包含了一个非常简单的脚本的代码。
<?php
$errors = '';
$myemail = 'lotusms@outlook.com';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address)) {
$errors .= "\n Error: Invalid email address";
}
if( empty($errors)) {
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n Email: $email_address \n Message \n $phone";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'index' page
header('Location: ../index.php');
}
?>
当然它也不起作用(或者我不会在这里,是吗?)...... :)
我使用以下测试文件对主机进行了测试,并获得了积极的“电子邮件发送!”这意味着服务器正在响应。
<?php
mail('lotusms@outlook.com','Test mail','The mail function is working!');
echo 'Mail sent!';
?>
那么,发生了什么?任何想法,或者你认为是积极的代码都会有效吗?
P.S。 HTML很简单
<form id="search" method="POST" name="contactform" action="contact-form-handler.php">
.....
<a onclick="document.getElementById('search').submit()">
<button type="submit" class="btn btn-default" value="SEND"/>Get Quote
</a>
提前致谢