0

在我的应用程序中,我使用 SMTP 发送电子邮件。我将电子邮件作为 html 电子邮件发送。

如果 html 内容很小,那么我可以使用 SMTP 正确发送电子邮件,但是当电子邮件消息包含冗长的 html 内容时,邮件不会最终出现在帐户中。

这是什么原因?

是否有任何命令或代码可以更改从客户端传递到 smtp 服务器的消息大小?

下面是我用来发送电子邮件的 SMTP 代码:

function smtp_mail($from, $to, $subject, $message, $headers="", $params=array()) {
    $errno = "";
    $errstr = "";
    $smtpConnect = fsockopen("mail2.allramhosting.com", "25", $errno, $errstr, 20);


    if (!empty($smtpConnect)) {

        if ($params['use_html']) {
            $extra_headers .= "MIME-Version: 1.0\nContent-Type: text/html; charset=\"utf-8\"\nContent-Transfer-Encoding: 7bit\n";
        }
        $headers = "To: " . $to . "\nFrom: " . $from . "\nSubject: " . $subject . "\nDate: " . date('r') . "\n" . $extra_headers . $headers;

        if (substr($headers, -1) == "\n") $headers = substr($headers, 0, -1); // Our last character should not be newline


        fputs($smtpConnect, "HELO networkssms.com\r\n");
        fputs($smtpConnect, "MAIL FROM: " . $from . " SIZE=1000000\r\n");
        fputs($smtpConnect, "RCPT TO: " . $to . "\r\n");
        fputs($smtpConnect, "DATA\r\n");
        fputs($smtpConnect, $headers . "\r\n\r\n");
        fputs($smtpConnect, $message . "\r\n.\r\n"); // send message and finish
        fputs($smtpConnect,"QUIT" . $newLine);
        fclose($smtpConnect);
        return true;
    }
    return false;
}

这是调用函数:

<?php
$subject = "UnTouched Ticket Notification";
$to = "example@gmail.com";
$from = "test@domain.com";
$part = "<html><body>\n";
$part .= "<div style='background-color: #EEEEEE;;padding: 10px 10px 20px;width: 650px; float:left;font-size:18px;'>\n";
$part1 = "<div style='width:500px;'>\n";

$part1 .= "<div style='width:450px;background-color:#eeeeee;padding: 30px 0 20px; height:auto; float:left;font-size:15px;margin-left:50px;'>\n";
$part3 = "</div></div></div>\n";
$part3 .= "</body></html>\n";

$center_part1 = 'Dear Admin ,';
$center_part = "You have opened 25 tickets . But the following tickets are not updated yet ,\n";
$center_part2="<div style='width:345px;color:#000000;font-size:12px;margin-left:25px; font-weight:bold; height:auto; margin-top:30px;'>\n";

$new = '<table height="92" style="border:2px solid #DCDCDC; width:565px;" cellspacing="0" cellpadding="0">
  <tr style="background-color:#E5E5E5;">
    <th height="35">Ticket #</th>
    <th>Customer</th>
    <th>Type</th>
    <th>Untouched Days</th>
    <th>Untouched Hours</th>
    <th>Last Updated Date</th>
  </tr>';
for($i=0;$i<100;$i++){
$new.= "<tr>
    <td align = 'center' height='30'>".$i."</td>
    <td align = 'center'>test</td>
    <td align = 'center'>terst</td>
    <td align = 'center'>".$i." Days</td>
    <td align = 'center'>".$i." Hours</td>
    <td align = 'center'>".$i."</td>
  </tr>";
}
$center_part2.=$new."</table></div>\n";
$message = $part.$center_part1.$part1.$center_part.$center_part2.$part3;
        if($to){
            smtp_mail($from, $to ,$subject, $message,"MIME-Version: 1.0\nContent-Type: text/html; charset=\"utf-8\"\nContent-Transfer-Encoding: 7bit\n");
        }

?>

你能确定这是什么原因吗?

4

1 回答 1

1

这是什么原因?

服务器就是这样配置的。

如果有任何命令或代码可以更改从客户端传递到 smtp 服务器的消息大小?

不。

于 2012-04-16T06:44:49.553 回答