我使用此代码从表单向我的电子邮件发送附件,但我面临两个问题: 1-有时它工作,有时停止工作 2 - 当我在我的电子邮件中收到附件时,我可以看到附件文件的大小,但它没有打开,而且单词文档文件是打开的,但它是空的同样的图片和excel文件和pdf任何人可以帮助????? < / p>
<?php
// Email address to which you want to send email
$to = 'xxx@xxx.com';
$subject = $_POST['fname'];
//$message = nl2br($_POST["fname"]);
/*********Creating Uniqid Session*******/
$txtSid = md5(uniqid(time()));
$headers = "";
$headers .= "From: ".$_POST['fname']."<".$_POST['femail'].">\r\nReply-To:
".$_POST['femail']."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"".$txtSid."\"\r\n\n";
$headers .= "This is a multi-part message in MIME format.\r\n";
$headers .= "--".$txtSid."\r\n";
$headers .= "Content-type: text/html; charset=utf-8\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n\n";
//$headers .= $message."\r\n\n";
/***********Email Attachment************/
if($_FILES['attachment']['name'] != "")
{
$txtFilesName = $_FILES['attachment']['name'];
$txtContent = chunk_split(base64_encode(file_get_contents($_FILES['attachment']
['tmp_name'])));
$headers .= "--".$txtSid."\r\n";
$headers .= "Content-Type: application/octet-stream; name=\"".$txtFilesName."\"\n";
$headers .= "Content-Transfer-Encoding: base64\n";
$headers .= "Content-Disposition: attachment; filename=\"".$txtFilesName."\"\r\n\n";
$headers .= $txtContent."\r\n\n";
}
// @ is for skiping Errors //
$flgSend=@mail($to,$subject,null,$headers);
if($flgSend)
{
echo "Email Sent SuccessFully, WelServ will contact you as soon as possible.<br/>you
will be redirected in 5 seconds<br/>";
echo "<script language='javascript'>window.setTimeout(function()
{location.href='hire.php'}, 5000)</script>";
}
else
{
$errorread=error_get_last();
echo '$errorread';
echo "Error in Sending Email, please try again, you will be redirected in 5
seconds!<br/>";
echo "<script language='javascript'>window.setTimeout(function()
{location.href='hire.php'}, 5000)</script>";
}
?>