1

我正在尝试将文件作为电子邮件附件发送,但由于某种原因,如果文件大于 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();
}
?>
4

2 回答 2

1

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

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

这应该会给你一个错误消息,说明如果它确实出错了怎么办。

于 2012-05-04T18:16:49.183 回答
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();
}
?>
于 2012-05-04T19:54:16.903 回答