带有附件的表格,结果喜忧参半


Form With Attachment Giving Mixed Results

嗨,我是一个网络程序员新手,最近为一个客户设计并编码了一个网站。他们要求联系人页面上的表格包含文件附件上传功能。我对PHP不太熟悉,但我做了一些研究,并设法在网上找到了一些代码,我已经在我的网站上实现了这些代码。我已经插入了我的电子邮件作为收件人,并实时测试了表单,附件文件工作正常,允许文件通过:)。然而,当消息传来时,我的电子邮件帐户(gmail)中似乎收到了一条警告消息,上面写着

"小心这条消息。类似的消息被用来窃取人们的个人信息。除非你信任发件人,否则不要点击链接或回复个人信息。"

我的问题是如何避免这种警报?我不希望我的客户在我将电子邮件更改为他作为收件人的帐户后必须处理此警报。此外,我已经收到一封来自随机人的电子邮件,要求我玩电子游戏垃圾邮件?我该如何避免这种情况?(我试着实现了一个重述,但我不喜欢这些,因为它们通常很难阅读)

此外,为什么我收到的电子邮件中没有显示要求"姓名"answers"电子邮件"的输入字段?只有"消息"字段信息会转发到我的电子邮件中。

非常感谢您的帮助。提前谢谢。

这是我目前拥有的PHP文件,它似乎在一定程度上起作用;

<?php
if(isset($_POST['submit']))
{
    //The form has been submitted, prep a nice thank you message
    $output = '<h1>Thanks for your file and message!</h1>';
    //Set the form flag to no display (cheap way!)
    $flags = 'style="display:none;"';
    //Deal with the email
    $to = 'christianmelchiordesign@gmail.com';
    $subject = 'a file for you';
    $message = strip_tags($_POST['message']);
    $name = strip_tags($_POST['name']);
    $email = strip_tags($_POST['email']);
    $attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name'])));
    $filename = $_FILES['file']['name'];
    $boundary =md5(date('r', time())); 
    $headers = "From: netzeroliving.ca'r'nReply-To: netzeroliving.ca";
    $headers .= "'r'nMIME-Version: 1.0'r'nContent-Type: multipart/mixed; boundary='"_1_$boundary'"";
    $message="This is a multi-part message in MIME format.
--_1_$boundary
Content-Type: multipart/alternative; boundary='"_2_$boundary'"
--_2_$boundary
Content-Type: text/plain; charset='"iso-8859-1'"
Content-Transfer-Encoding: 7bit
$message
--_2_$boundary--
--_1_$boundary
Content-Type: application/octet-stream; name='"$filename'" 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 
$attachment
--_1_$boundary--";
    mail($to, $subject, $message, $headers);
}
?>

^^^我必须注意,上面的PHP代码被放置在body标记之外。。。不确定这是否应该放在正文标签中^^

<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>"    method="post"   <?php echo $flags;?>>

            <p class="name">
                <input type="text" name="name" id="name" />
                <label for="name">Name</label>
            </p>
            <p class="email">
                <input type="text" name="email" id="email" />
                <label for="email">E-mail</label>
            </p>

            <p>
                <label for="message">Message</label> 
                <textarea name="message" id="message" cols="20" rows="8"></textarea>
            </p>
            <p>
                <label for="file">File</label> 
                <input type="file" name="file" id="file">
            </p>
            <p>
                <input type="submit" name="submit" id="submit" value="send">
            </p>
</form>

^^^上面的编码被放置在正文标签^^

将发件人地址设置为实际的电子邮件地址,如NOREPLY@netzeroliving.ca.现在看来,您发送的邮件没有正确的电子邮件地址。

此外,请将主题改为听起来不像病毒垃圾邮件的内容。

关于未显示的名称/电子邮件,它似乎没有放在消息中的任何位置(查找$email和$name)。

关于垃圾邮件,请查看此问题。