PHPMailer和附件的100K文件限制?

时间:2012-05-04 18:06:29

标签: php iis phpmailer

我正在尝试将文件作为电子邮件附件发送,但出于某种原因,如果该文件是> 100k然后电子邮件没有通过,即使我收到电子邮件发送消息 它也可能是IIS smtp设置中附件的限制,但是当我取消选中限制会话大小和限制邮件大小选项时,它不会更改任何内容。我今晚可能要重启服务器......

我不知道它是php.ini设置,还是什么。

<?
$path_of_attached_file = "Images/marsbow_pacholka_big.jpg";

require 'include/PHPMailer_5.2.1/class.phpmailer.php';
try {
    $mail = new PHPMailer(true); //New instance, with exceptions enabled

    $body = $message; //"<p><b>Test</b> another test 3.</p>";

    $mail->AddReplyTo("admin@example.com","Admin");

    $mail->From     = "admin@example.com";
    $mail->FromName = "Admin";

    $mail->AddAddress($to);
    $mail->Subject  = "First PHPMailer Message";
    $mail->AltBody  = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
    $mail->WordWrap = 80; // set word wrap

    $mail->MsgHTML($body);

    $mail->IsHTML(true); // send as HTML
    if($attach){
        $mail->AddAttachment($path_of_attached_file);
    }

    $mail->Send();
    echo 'Message has been sent.';
} catch (phpmailerException $e) {
    echo $e->errorMessage();
}
?>

2 个答案:

答案 0 :(得分:1)

您的代码实际上并未检查邮件是否已发送。 您需要更改代码以检查send方法的返回

if ($mail->Send())
  echo 'Message has been sent.';
else
  echo 'Sorry there was an error '.$mail->ErrorInfo;

这应该会给你一个错误信息,说明如果它出错了会发生什么。

答案 1 :(得分:1)

我可能错了,因为我不使用IIS,但您提供的代码实际上使用的是本机MTA而不是SMTP。据我所知,您必须使用IsSMTP()方法让PHPMailer知道您打算使用SMTP。

这样的事情:

<?
$path_of_attached_file = "Images/marsbow_pacholka_big.jpg";

require 'include/PHPMailer_5.2.1/class.phpmailer.php';
try {
    $mail = new PHPMailer(true); //New instance, with exceptions enabled

    $body = $message; //"<p><b>Test</b> another test 3.</p>";
    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->Host       = "mail.yourdomain.com"; // SMTP server
    $mail->SMTPDebug  = 2;
    $mail->SMTPAuth   = true;                  // enable SMTP authentication
    $mail->Host       = "mail.yourdomain.com"; // sets the SMTP server
    $mail->Port       = 25;                    // set the SMTP port 
    $mail->Username   = "yourname@yourdomain"; // SMTP account username
    $mail->Password   = "yourpassword";        // SMTP account password 

    $mail->AddReplyTo("admin@example.com","Admin");

    $mail->From     = "admin@example.com";
    $mail->FromName = "Admin";

    $mail->AddAddress($to);
    $mail->Subject  = "First PHPMailer Message";
    $mail->AltBody  = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
    $mail->WordWrap = 80; // set word wrap

    $mail->MsgHTML($body);

    $mail->IsHTML(true); // send as HTML
    if($attach){
        $mail->AddAttachment($path_of_attached_file);
    }

    $mail->Send();
    echo 'Message has been sent.';
} catch (phpmailerException $e) {
    echo $e->errorMessage();
}
?>