0

我在一个网站上使用一个基本的 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

非常感谢您的帮助!

4

1 回答 1

1

您必须考虑在您的邮件表单中实施验证码,以便自动脚本不会从您的域发送邮件。验证码还确保您将某些字段设置为required(不仅使用 js 验证,还使用服务器端 php 代码验证)。

于 2013-02-28T03:18:27.547 回答