发送附件有问题的邮件

时间:2013-07-23 20:12:37

标签: php email

我发送带附件的邮件时遇到问题。我有这个功能:

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。这使得所有更简单,它的工作原理。我所有的工作都没有。

1 个答案:

答案 0 :(得分:0)

您使用PHP的内置mail()函数发送消息。

因此,PHP将尝试通过运行PHP的同一服务器上运行的本地MTA发送消息,如sendmail_path文件中php.ini所指定的那样。您首先要查看本地MTA的日志 这些应该告诉你

  1. 本地MTA是否收到来自PHP脚本的消息,如果是,
  2. 本地MTA尝试将邮件传递到远程MTA时发生了什么。