PHP邮件表格:邮件是空白的

时间:2015-07-20 16:59:45

标签: php html email

我是初学者,我想制作一个类似的PHP邮件表单:

Screenshot

但它不起作用,我收到邮件但是里面有任何东西,我不明白为什么:/

以下是我的表单的HTML代码:

<form method=POST action=formmail.php >
    <input type=hidden name=subject value=formmail>


<p>Pseudo* :<br>
    <span class="padding1"><input type="text" name="your-name" value="" size="40" aria-required="true" aria-invalid="false"></span> </p>
<p>Email* :<br>
    <span class="your-email padding1"><input type="email" name="your-email" value="" size="40" aria-required="true" aria-invalid="false"></span> </p>
<p>Link of the GIF* :<br>
    <span class="link-url padding1"><input type="url" name="link-url" value="" aria-invalid="false"></span> </p>

<p><input type="submit" value="Send"><img class="ajax-loader" src="http://s584101063.onlinehome.fr/wp-content/plugins/contact-form-7/images/ajax-loader.gif" alt="Envoi en cours ..." style="visibility: hidden;"></p>
</div>
</form>

这是我的PHP代码:

    <?php
$TO = "saintscorporation@gmail.com";

$h = "From: " . $TO;

$message = "";

while (list($key, $val) = each($HTTP_POST_VARS)) {
$message .= "$key : $val\n";
}

mail($TO, $subject, $message, $h);

Header("Location: http://gifmyday.com/index.html");

?>

1 个答案:

答案 0 :(得分:1)

添加我在下面的代码中添加的标题应该会有所帮助。

<?php
$TO = "saintscorporation@gmail.com";

// The headers have been changed a bit
$h = "From: " . $TO . "\r\n";
$h .= "MIME-Version: 1.0 \r\n" . 
    "Content-type: text/html charset=iso-8859-1 \r\n";

$message = "";

while (list($key, $val) = each($HTTP_POST_VARS)) {
$message .= "$key : $val\n";
}

mail($TO, $subject, $message, $h);

Header("Location: http://gifmyday.com/index.html");

?>