使用php mail()。所有代码都运行良好,但附件为空

时间:2019-03-13 07:17:21

标签: php

代码运行正常。它正在发送邮件,但我将与此邮件一起发送的附件。有附件显示,它也正在下载,但这是空的。正在显示1kb的大小。我已将所有必要的代码和属性放在正文,标题中。尽管如此,显示附件为空。这是代码问题还是服务器?双方都没有错误。邮件已发送,只是附件为空。

/* Email Detials */
$filename = '121 tech.jpg';
$path = 'http://121techtraining.in';
$file = $path . "/" . $filename;

$mailto = $cpmail;
$subject2 = 'Reeytal - Registration for TTT Workshop';
$message2 = 'Dear Participant';


$content = file_get_contents($file);
$content = chunk_split(base64_encode($content));

// a random hash will be necessary to send mixed content
$separator = md5(time());

// carriage return type (RFC)
$eol = "\r\n";

// main header (multipart mandatory)
$headers = "From: Ree-Ytal Consultancy <helpdesk@121techtraining.in >" . $eol;
$headers .= "MIME-Version: 1.0" . $eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol;
$headers .= "Content-Transfer-Encoding: 7bit" . $eol;
$headers .= "This is a MIME encoded message." . $eol;

// message
$body = "--" . $separator . $eol;
$body .= "Content-Type: text/plain; charset=\"iso-8859-1\"" . $eol;
$body .= "Content-Transfer-Encoding: 8bit" . $eol;
$body .= $message2 . $eol;

// attachment
$body .= "--" . $separator . $eol;
$body .= "Content-Type: application/octet-stream; name=\"" . $filename . "\"" . $eol;
$body .= "Content-Transfer-Encoding: base64" . $eol;
$body .= "Content-Disposition: attachment" . $eol;
$body .= $content . $eol;
$body .= "--" . $separator . "--";

mail($mailto, $subject2, $body, $headers);

0 个答案:

没有答案