-2

我正在为一个网站编写联系表格,但无法让它在实际电子邮件中发送我的表格字段。

电子邮件已成功发送和接收。

这是我的 HTML

<form action="mail.php" method="post" style="font-size:12px;">
            <p>Name</p> <input type="text" name="name">

            <p>Telephone</p><input type="text" name="phone" size="30" />

            <p>Email</p> <input type="text" name="email">

            <p>Message</p><textarea name="comments" rows="6" cols="25"></textarea><br />

            <p>Best time to Contact You</p><input type="text" size="15" name="time" />

            <input type="submit" value="Send"><input type="reset" value="Clear">
        </form>

和我的 PHP

    <?php
$to = "myemailaddress";
$subject = "New Website Enquiry";
$message = "You have recieved a new enquiry";
$from = $_POST['email'];
$name = $_POST['name'];
$message = $_POST['comments, phone, time'];

$headers = "From:" . $from;


$url = 'index.html';
    echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
mail($to,$subject,$message,$headers);
?>
4

3 回答 3

1

您需要学习基本的 PHP 语法。

$message = $_POST['comments, phone, time'];

是完全错误的。您不能在这样的逗号分隔列表中指定多个数组键,更不用说在 STRING 中了。代码应该更像:

$message = $_POST['comments'] . $_POST['phone'] . $_POST['time'];

请注意,您所拥有的不是php 级别的语法错误。您正在使用一个完全可以接受的数组键,它恰好不存在。

于 2013-07-24T18:19:11.707 回答
0
<?php 

$to = "myemailaddress"; 
$subject = "New Website Enquiry"; 
$message = "You have recieved a new enquiry"; 
$from = $_POST['email']; 
$name = $_POST['name']; 
$headers = "From:" . $from; 
$url = 'index.html'; 
echo '<META HTTP-EQUIV=Refresh CONTENT="0;URL='.$url.'">'; mail($to,$subject,$message,$headers); 

?>
于 2013-07-24T18:21:32.170 回答
0

我在您的代码中发现了一个语法错误:

改变

$message = $_POST['comments, phone, time'];

$message = $_POST['comments'] . . $_POST['phone'] . $_POST['time'];

你还有什么问题?

于 2013-07-24T18:18:29.717 回答