-1
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$priority = $_POST['priority'];
$type = $_POST['type'];
$website = $_POST['website'];
$message = $_POST['message'];

$mail_to = 'info@mohdify.net';
$subject = 'Message from a site visitor '.$subject;

$body_message = "From: $name\n";
$body_message .= "E-mail: $email\n";
$body_message .= "Phone: $phone\n";
$body_message .= "Priority: $priority\n";
$body_message .= "Type: $type\n";
$body_message .= "Website: $website\n";
$body_message .= "Message: $message";

$headers = "From: $email";
$headers .= "Reply-To: $email";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
        alert('Thank you for the message. We will contact you shortly.');
        window.location = 'contact_page.html';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Message failed. Please try ');
        window.location = 'contact_page.html';
    </script>
<?php
}
?>

这是 PHP 文件,但每次我尝试时,我都可以收到消息,但它不包含输入的值。

收到的电子邮件看起来像这样

From: 
E-mail: 
Phone: 
Priority: 
Type: 
Website: 
Message: 

有人可以帮我解决我的问题吗?

谢谢,

4

3 回答 3

0

您可以尝试使用sprintfwith$_REQUEST而不是$_POST,不那么不安全,因为$_REQUEST会同时查看postandget和其他各种..

<?php
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$priority = $_REQUEST['priority'];
$type = $_REQUEST['type'];
$website = $_REQUEST['website'];
$message = $_REQUEST['message'];

$mail_to = 'info@mohdify.net';
$subject = sprintf("Message from a site visitor  %s\n", $subject);

$body_message = sprintf("From: %s\n", $name);
$body_message .= sprintf("E-Mail: %s\n", $email);
$body_message .= sprintf("Phone: %s\n", $phone);
$body_message .= sprintf("Priority: %s\n", $priority);
$body_message .= sprintf("Type: %s\n", $type);
$body_message .= sprintf("Website: %s\n", $website);
$body_message .= sprintf("Message: %s\n", $message);

$headers = sprintf("From: %s\n", $email);
$headers .= sprintf("Reply-To: %s\n", $email);

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
        alert('Thank you for the message. We will contact you shortly.');
        window.location = 'contact_page.html';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Message failed. Please try ');
        window.location = 'contact_page.html';
    </script>
<?php
}
?>
于 2013-10-11T02:51:20.517 回答
0
<form id="contact-form" action="mail.php" method="POST">
            <h3>Get in touch</h3>
            <h4>Fill in the form below, and we'll get back to you within 24 hours.</h4>
            <div>
                <label>

                    <span>Name: (required)</span>
                    <input placeholder="Please enter your name" type="text" name="name" required autofocus>
                </label>
            </div>
            <div>
                <label>
                    <span>Email: (required)</span>
                    <input placeholder="Please enter your email address" type="email" name="email" tabindex="2" required>
                </label>
            </div>
            <div>
                <label>
                    <span>Telephone: (required)</span>
                    <input placeholder="Please enter your number" type="tel" name="phone" tabindex="3" required>
                </label>
            </div>
            <div>
                <label>
                    <span>What do you look for? (required)</span>
                    <select name="priority" size="1">
                    <option value="Low">Choose from these</option>
                    <option value="Normal">Option 1</option>
                    <option value="High">Option 2</option>
                    <option value="Emergency">Option 3</option>
                    </select>               </label>
            </div>
            <div>
                <label>
                    <span>Type: (required)</span>
                    <select name="type" size="1">
                    <option value="update">Personal</option>
                    <option value="change">Small Business</option>
                    <option value="addition">Professional</option>
                    </select>
                </label>
            </div>

            <div>
                <label>
                    <span>Website: (required)</span>
                    <input placeholder="Begin with http://" type="url"name="website" tabindex="4" >
                </label>
            </div>
            <div>
                <label>
                    <span>Message: (required)</span>
                    <textarea placeholder="Include all the details you can" tabindex="5" name="message" required></textarea>
                </label>
            </div>
            <div>
                <button name="submit" type="submit" id="contact-submit" value="send">Send Email</button>
            </div>
        </form>
于 2013-10-12T22:08:09.487 回答
0

先给我看看你的 HTML。

确保您已method="post"为表单设置。此外,检查输入的名称 - 它们必须匹配 POST 数组中的变量。

于 2013-10-11T02:45:41.590 回答