我在发送带有附件的邮件时遇到问题。我有这个功能:
function mail_att($to, $subject, $message, $anhang) {
$absender = "Sender";
$absender_mail = "noreply@example.org";
$reply = "noreply@example.org";
$path = $anhang;
$uploadname = "Anhang.pdf";
$trenner = md5( time() );
// Mail Header
$mailheader = "Reply-To: " .$absender. "<" .$absender_mail. ">\r\n";
$mailheader .= "Return-Path: ".$absender_mail."\r\n";
$mailheader .= "Message-ID: <".$absender_mail.">\r\n";
$mailheader .= "X-Mailer: PHP v" .phpversion(). "\r\n";
$mailheader .= "From: ".$absender."<".$absender_mail.">\r\n";
$mailheader .= "MIME-Version: 1.0\r\n";
$mailheader .= "Content-Type: multipart/mixed;\r\n";
$mailheader .= " boundary = " .$trenner;
$mailheader .= "\r\n\r\n";
// Mailbody
$mailbody = "This is a multi-part message in MIME format\r\n";
$mailbody .= "--" .$trenner. "\r\n";
$mailbody .= "Content-Type: text/html; charset=UTF-8\r\n";
$mailbody .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
$mailbody .= $message. "\r\n\r\n";
// Attachment
$mailbody .= "--" .$trenner. "\r\n";
$mailbody .= "Content-Type: application/pdf; name=\"" .$uploadname. "\"\r\n";
$mailbody .= "Content-Transfer-Encoding: base64\r\n";
$mailbody .= "Content-Disposition: attachment; filename=\"" .$uploadname. "\"\r\n\r\n";
$mailbody .= chunk_split( base64_encode( file_get_contents( $path ) ) );
$mailbody .= "\n";
// Send
mail( $to, htmlspecialchars( $subject ), $mailbody, $mailheader );
}
但是当我想发送邮件时,我什么也得不到。问题出在哪里?我确定我输入了正确的接收者电子邮件!并且邮件服务器没有问题,因为正常的电子邮件工作正常。
解决了
哦,我从没想过要使用phpmailer。这使一切变得更简单并且有效。我所有的工作都是徒劳的。