0

我没有通过电子邮件 mail@example.com 收到邮件。下面是我的表单代码和我的 send-mail.php 代码。任何人都可以帮我解决这个问题,因为一切似乎都很好,但我没有收到任何电子邮件。我使用 localhost 作为服务器。

联系表:

<form id="contactForm" action="#" method="post">
<p>Email us by filling in the form below. Make sure you fill in the message and all fields.</p>
<fieldset>
<div>
<input name="name"  id="name" type="text" class="form-poshytip" title="Enter your name" />
<label>Name</label>
</div>
<div>

<input name="web"  id="web" type="text" class="form-poshytip" title="Enter your surname" />
                                     <label>Surname</label>
</div>
<div>
<input name="email"  id="email" type="text" class="form-poshytip" title="Enter your email address" />
                                    <label>Email</label>
</div>

<div>
<textarea  name="comments"  id="comments" rows="5" cols="20" class="form-poshytip" title="Enter your comments"></textarea>
</div>

<!-- send mail configuration -->
<input type="hidden" value="mail@example.com" name="to" id="to" />
<input type="hidden" value="Enter the subject here" name="subject" id="subject" />
<input type="hidden" value="send-mail.php" name="sendMailUrl" id="sendMailUrl" />
<!-- ENDS send mail configuration -->

<p><input type="button" value="Send" name="submit" id="submit" /> <span id="error" class="warning">Message</span></p>
</fieldset>

</form>
<p id="sent-form-msg" class="success">Form data sent. Thanks for your feedback.</p>
<!-- ENDS form -->

这是send-mail.php

<?php
//vars
$subject = $_POST['subject'];
$to = explode(',', $_POST['to'] );

$from = $_POST['mail@example.com'];

//data
$msg = "NAME: "  .$_POST['name']    ."<br>\n";
$msg .= "EMAIL: "  .$_POST['email']    ."<br>\n";
$msg .= "WEBSITE: "  .$_POST['web']    ."<br>\n";
$msg .= "COMMENTS: "  .$_POST['comments']    ."<br>\n";

//Headers
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: <".$from. ">" ;


//send for each mail
foreach($to as $mail){
mail($mail, $subject, $msg, $headers);
}

?>
4

3 回答 3

1
$_POST['subject'];

$_POST['to'];

$_POST['myemail@gmail.com'];

$_POST['name'];

$_POST['email'];

$_POST['web'];

$_POST['comments'];

我没有在您的表单中找到任何这些元素。这就是为什么什么都没有发生的原因。尝试

echo '<pre>';
print_r($_POST);

这将在提交表单时为您提供发布的数组。

于 2013-04-11T05:33:09.553 回答
0

我有一些建议。如果您将“收件人”地址隐藏在表单中,那么为什么您不能尝试将其直接保留在 sendmail 功能中,而您尝试保留在 $from 中

<?php
$to="kurtfarrugia92@gmail.com";
$from =$_POST['field_name']; 
// not the mail id because i didn't see any field with name as "kurtfarrugia92@gmail.com"
?>
于 2013-04-11T05:50:11.747 回答
0

您不能使用此功能从本地主机发送邮件。我不确定,但您应该尝试使用PHP 邮件程序来完成此任务。

于 2013-04-11T06:05:26.523 回答