Php联系表单编码问题

时间:2015-11-09 14:36:59

标签: php html forms email post

我在为我的网站创建的联系表单时遇到问题。我不是PHP专家,但我认为一个合适的联系表单比一个简单的href mailto链接更专业。 我设法收到了电子邮件,它告诉我发件人,但没有主题,只是没有文字的空白。此外,我每天都会收到来自任何发件人的2封电子邮件。

这是我在PHP中在名为contact.php的页面中所做的。 我希望你能提供帮助:

<?php 
$name = $_POST['name'];
$email = $_POST['email'];
$form1_services = $_POST['form1_services'];
$msg = $_POST['msg'];
$formcontent="From: $name \n Message: $message";
$recipient = "dandrea.alessandro81@gmail.com";
$subject = "Customer Inquiry";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You! Keep in touch soon!" . " -" . "<a href='index.html'           style='text-decoration:none;font-family: 'gooddogregular';color:#009999;'>     Return Home</a>";

&GT;

这是HTML中的实际形式:

<form action="contact.php" method="post">
    <fieldset>
        <legend></legend>
        <div class="controlgroup">
            <label for="form1_name">Name *</label>
                <input type="text" placeholder="Enter your full name*" name="name" value>
        </div>
        <div class="controlgroup">
            <label for="form1_email">Email *</label>
                <input type="text" placeholder="Enter a valid email address*" name="email" value>
        </div>
        <div class="controlgroup">
            <label for="form1_services">Services Required</label>
                <select id="form1_services" name="services">
                    <option value="Website Design"> Website Design (from scratch) </option>
                    <option value="Resposive Design"> Responsive Design </option>
                    <option value="Customize a Site"> Customize a Site </option>
                    <option value="Quotation"> Quotation </option>
                </select>
        </div>
        <div class="controlgroup">
            <label>Project Info*</label>
                <textarea placeholder="Ciao Alessandro, I am contacting you because...*" id="msg" name="msg" required aria-required="true"></textarea>
        </div>
            <input type="submit" name="submit_btn" id="send" value="Hit me up!" class="wow rubberBand animated" data-wow-delay="2s">
    </fieldset>         
</form>

提前多多感谢。 的Alessandro

2 个答案:

答案 0 :(得分:1)

看看你的PHP,你收集了很多字段,然后没有实际使用它们。试试这个:

<?php 
$name = $_POST['name'];
$email = $_POST['email'];
$form1_services = $_POST['services'];
$msg = $_POST['msg'];

$message = 'From: ' . $name . ' <' . $email . '>' . "\n";
$message .= 'Service: ' . $form1_services . "\n";
$message .= 'Message: ' . "\n";
$message .= $msg;

$recipient = "dandrea.alessandro81@gmail.com";
$subject = "Customer Inquiry";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $message, $mailheader) or die("Error!");
echo "Thank You! Keep in touch soon!" . " -" . "<a href='index.html'           style='text-decoration:none;font-family: 'gooddogregular';color:#009999;'>     Return Home</a>";

请注意,此时,您实际上并未验证任何此类信息,因此您无法确定电子邮件地址或名称是否真的有效,但这应该是至少告诉你发布的内容。

答案 1 :(得分:0)

尝试添加一些标题:

    $mailheader = "From: $email \r\n";
    $mailheader .= "MIME-Version: 1.0\r\n";
    $mailheader .= "Content-Type: text/html; charset=ISO-8859-1\r\n";