我无法通过自定义PHP邮件发送附件。邮件发送正确,图片在服务器中正确上传,但附件没有通过电子邮件到达。这可能有什么问题?这是我的sendmail
authSendEmail($email, $name, $to, $WSiteCompany, "Business Opportunity", $message, $target_file);
这是我的发送邮件代码。我没有想法?这可能是服务器问题还是代码问题?请协助
//Attachment
$filename = basename($filePath); // Filename that will be used for the file as the attachment
var_dump($filename);
$file_size = filesize($filePath);
$handle = fopen($filePath, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$fext = strtolower(substr(strrchr(basename($filename),"."),1));
$mtype = '';
$allowed_ext = array (
// images
'gif' => 'image/gif',
'png' => 'image/png',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg'
);
if ($allowed_ext[$fext] == '') {
// mime type is not set, get from server settings
if (function_exists('mime_content_type')) {
$mtype = mime_content_type($filePath);
}
else if (function_exists('finfo_file')) {
$finfo = finfo_open(FILEINFO_MIME); // return mime type
$mtype = finfo_file($finfo, $filePath);
finfo_close($finfo);
}
if ($mtype == '') {
$mtype = "application/force-download";
}
}
else {
// get mime type defined by admin
$mtype = $allowed_ext[$fext];
}
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/html; charset=utf-8\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type:".$mtype."; name=\"".$filename."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= "--".$uid."--";
fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$header\n\n$message\n.\n");
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data2response'] = "$smtpResponse";