在php中创建一个简单的邮件表单

时间:2013-05-26 14:05:41

标签: php forms email

好的,所以我一直在尝试在php中创建一个非常简单的订单系统,它包含一页不同的表单字段,您填写并提交,当提交了一个将发送邮件的验证页面,或者声明错误。它工作了一个星期左右,然后我对文件进行了微小的更改并上传了它们,并将它们更改回来。现在它拒绝工作。这是我的两个页面的代码:

</head>
<body>
    <form name="detaljer" action="index.php" onsubmit="return validateForm();" 
          method="POST">
        <p>Ange önskad kaliber</p>
        <select name="kaliberCombo">
            <option value=".22">.22</option>
            <option value="9mm">9x19mm</option>
            <option value=".40">.40</option>
            <option value=".45">.45</option>
            <option value=".357">.357</option>
            </select>
        </br>
            <p>Declare number:</p>
            <input type="number" name="antal" min="100">
            <p>Name*:</p><input type="text" name="fnamn"><input type="text" name="enamn">
            <p>Email*:</p><input type="text" name="email">
            <p>Adress:</p><input type="text" name="address">
            <p>Phone*:</p><input type="text" name="telefon">
            <br>
            <p>Add a comment</p>
            <textarea name="comment" rows="5" cols="50" maxlength="300">

            </textarea>
    <input type="submit" value="submit">
    <br><p>* required fields</p>

    </form>
    <script src="js/main.js"></script>
</body>

Theres上面也有一些jscript,虽然这不重要。

然后是验证页面:

    <!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <?php

$kaliber=$_POST['kaliberCombo'];
$antal = $_POST['antal'];
$fornamn = $_POST['fnamn'];
$efternamn = $_POST['enamn'];
$mail = $_POST['email'];
$address = $_POST['address'];
$telefon = $_POST['telefon'];
$kommentar = $_POST['comment'];        


$sender = "Anyname";
$sendername = "examplemail@example.com";
$recipient = "gbreisch@hotmail.com";
$recipientname = "gbreisch";
$subject = "Bestallning!";
$message = "Bestallning \n
$fornamn $efternamn har beställt    
\n'$antal'st $kaliber \n
Email: $mail\n
Telefon: $telefon\n
Kommentar som gavs av kund: $kommentar";


$date = date(DATE_RFC2822);
$mid = "<" . sha1(microtime()) . "@" . $_SERVER['HTTP_HOST'] . ">";


mb_internal_encoding("UTF-8");


$sendername = mb_encode_mimeheader($sendername);
$recipientname = mb_encode_mimeheader($recipientname);

$headers =<<<EOT
From: $sendername <$sender>
Date: $date
Message-ID: $mid
MIME-Version: 1.0 
Content-Type: text/plain; charset="UTF-8"
EOT;

$status = mb_send_mail("$recipientname <$recipient>", $subject, $message, $headers, "-f$sender");
if(!$status) {
        echo "Could not send your order.";
}
else {
        echo "Order sent!";
}?>
    </body>
</html>

由于最近代码工作正常,这让我很疯狂,而且我尝试使用旧版本,它拒绝发送。

1 个答案:

答案 0 :(得分:0)

首先,如果网络服务器阻止了您的邮件,您应该尝试通过表单发送电子邮件并查看垃圾邮件文件夹。