我发送带附件的邮件时遇到问题。我有这个功能:
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。这使得所有更简单,它的工作原理。我所有的工作都没有。
答案 0 :(得分:0)
您使用PHP的内置mail()
函数发送消息。
因此,PHP将尝试通过运行PHP的同一服务器上运行的本地MTA发送消息,如sendmail_path
文件中php.ini
所指定的那样。您首先要查看本地MTA的日志
这些应该告诉你