我正在制作一个 PHP 表单,允许用户上传附件并将其发送到我的电子邮件。我一直在寻找很长时间才能做到这一点。最后,我找到了这个。http://www.shotdev.com/php/php-mail/php-send-email-upload-form-attachment-file/。它工作正常。但是,当我自己修改它(更改字段)时,有些事情并不顺利。
<?php
$location=$_POST['location'];
$name_ha=$_POST['name_ha'];
$name_person=$_POST['name_person'];
$email=$_POST['email'];
$date_sent=$_POST['date_sent'];
$date_completed=$_POST['date_completed'];
$date_received=$_POST['date_received'];
$to="admin@admin.com" . "$email";
$message="to";
//*** Uniqid Session ***//
$sid = md5(uniqid(time()));
$header = "";
$header .= "From: ".$_POST["name_ha"]."<".$_POST["email"].">\nReply-To: ".$_POST["email"]."";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$sid."\"\n\n";
$header .= "This is a multi-part message in MIME format.\n";
$header .= "--".$sid."\n";
$header .= "Content-type: text/html; charset=utf-8\n";
$header .= "Content-Transfer-Encoding: 7bit\n\n";
$header .= $message."\n\n";
//*** Attachment ***//
if($_FILES["fileAttach"]["name"] != "")
{
$FilesName = $_FILES["fileAttach"]["name"];
$Content = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"])));
$header .= "--".$sid."\n";
$header .= "Content-Type: application/octet-eam; name=\"".$FilesName."\"\n";
$header .= "Content-Transfer-Encoding: base64\n";
$header .= "Content-Disposition: attachment; filename=\"".$FilesName."\"\n\n";
$header .= $Content."\n\n";
}
$flgSend = @mail($to,"A new file for you!",null,$header); // @ = No Show Error //
if ($flgSend)
{
echo "Mail sent.";
}
?>
我从 shotdev.com 下载的文件和我修改的文件托管在同一台服务器上和同一文件夹下。但是,对于我修改过的那个,如果文件大小大于 1MB,则在上传附件之前发送电子邮件(大约 45% 的上传过程)。我收到的电子邮件,没有附件,也没有发件人($name_ha)的信息。另一方面,对于在shotdev.com上下载的文件,无论多大的附件,只有在附件完全上传后才会发送电子邮件。
脚本是否有任何错误,或者缺少某些内容,导致发生这种情况?非常感谢您的时间和帮助。