我在网站上使用基本的PHP邮件表格&我的客户已经向我提到他每天都会收到一封随机的电子邮件,他的收件箱完全是空白的。我读到了这个问题,并且认为邮件表单每次加载页面时都会发送一封电子邮件,这是正确的吗?或者这是另一个问题吗?
PHP
<?php
$mail_to = "email1@gmail.com, email2@gmail.com"; // specify your email here
// Assigning data from the $_POST array to variables
$name = $_POST['sender_name'];
$mail_from = $_POST['sender_email'];
$phone = $_POST['sender_phone'];
$web = $_POST['sender_web'];
$company = $_POST['sender_company'];
$addy = $_POST['sender_addy'];
$message = $_POST['sender_message'];
// Construct email subject
$subject = 'Web Prayer Request from ' . $name;
// Construct email body
$body_message = 'From: ' . $name . "\r\n";
$body_message .= 'E-mail: ' . $mail_from . "\r\n";
$body_message .= 'Phone: ' . $phone . "\r\n";
$body_message .= 'Prayer Request: ' . $message;
// Construct email headers
$headers = 'From: ' . $name . "\r\n";
$headers .= 'Reply-To: ' . $mail_from . "\r\n";
$mail_sent = mail($mail_to, $subject, $body_message, $headers);
if ($mail_sent == true){ ?>
<script language="javascript" type="text/javascript">
alert('Your prayer request has been submitted - thank you.');
window.location = 'prayer-request.php';
</script>
<?php } else { ?>
<script language="javascript" type="text/javascript">
alert('Message not sent. Please, notify the site administrator info@info.com');
window.location = 'prayer-request.php';
</script>
<?php
}
?>
网站链接:http://tinyurl.com/dy48jom
非常感谢您的帮助!
答案 0 :(得分:1)
您必须考虑在邮件表单中实施验证码,以便自动脚本不会从您的域发送邮件。captcha还要确保您将某些字段设为required
(不仅验证使用js但也使用服务器端的PHP代码)。