Member Avatar


I've been using a php script to send simple emails (no attachment).
Suddenly I discovered that when making the body of the letter longer
than 5323 bytes, it appeared to be sent but was not.

I'm using direct SMTP, and no "PHPmailer" because it's just too
complicated -- and I'm not using mail() because it causes too many

Does anyone know how to avoid this limitation -- because I know it
can be done -- the documented limit is 10MB !!!

For anyone interested, here's the code. It splits the message body
into several records, but that didn't help. I've still kept that
code though, because I don't think it's smart to send too large

The script is not intended to handle appendices etc.


$long = file_get_contents ("testletter.txt");   // This is the mail body!!!
$to = "my name <>";       // Replace these for testing
$from = "The Sender <>";
$subject = "MAIL TEST";

SMTPsend ($from, $to, $subject, $long);

function SMTPsend ($to, $from, $subject, $body)
{   define (LF, "\n");           // Normal linefeed
    define (CRLF, "\r\n");       // Always used by SMTP.

    if ($_SERVER["SERVER_ADDR"])
        define (BR, "<br />");       // HTML linefeed
        define (BR, LF);             // Normal linefeed

//    Build header lines. Remember TWO linefeeds at the end!
    $header = <<<headend
To: $to
From: $from
Subject: $subject
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-Mailer: SMTPsend 2.0


    $smtp_host = "ssl://";   // Change these!
    $smtp_port = 465;
    $smtp_user = "";
    $smtp_pass = "My SeCrEt PaSsWoRd";

// Only addresses, with brackets
    if ( ($p = strpos($to,"<") ) > 0)
        $smtp_to = substr ($to,$p);
        $smtp_to = "<$to>";

    if ( ($p = strpos($from,"<") ) > 0)
        $smtp_from = substr ($from,$p);
        $smtp_from = "<$from>";

//    Open socket
    $smtp_server = @fsockopen($smtp_host, $smtp_port, $errno, $errstr, 30)
    or die("Attempting connection to $smtp_host on port $smtp_port failed!"
    .BR."Connection refused on $smtp_host at port $smtp_port.");

    {    error_log ("Sending to ".$smtp_host." failed!".LF,3,ERRORLOG);
        print "Connection to $smtp_host on port $smtp_port failed!"
        .BR."[$errorno] $errorstr";
        return false;

."MAIL FROM:$smtp_from".CRLF
."RCPT TO:$smtp_to".CRLF

    fwrite($smtp_server, $header);

    $max = 2048;           // Max record length
    $start = $end = 0;

    echo "Body length: ".strlen($body).BR;
    {   $end = min (strlen($body),$start+$max);
        $len = $end-$start;
//      echo "Start = $start, End = $end".BR;
        fwrite($smtp_server, substr ($body,$start,$len));
        $start += $len;
    } while ($start < strlen($body));

    fwrite($smtp_server, CRLF.CRLF.".".CRLF."QUIT".CRLF);
    error_log ("Sending complete.".LF,3,ERRORLOG);
    return true;
Member Avatar


I have not found the error per se, but I started over and included checking
of the SMTP server responses, so I now have a working test script.

If anyone is interested (still without appendix/multipart capability) I will make it available. Just send an e-mail from here: