oh, I misread the substr manual, I thought that the 3rd argument is the end position, it should be length.

Rickard wrote:

substr($mail_tpl, 8, $first_crlf-8);

==

Get $first_crlf-8 characters starting at position 8. If we didn't subtract 8 from the length, we would get characters from the next line.

why? 
e.g. in welcome.tpl:
Subject: Welcome to <board_title>!\n

substr($mail_tpl, 8, $first_crlf-8)

The first 8 make $mail_subject starts after 'Subject'.  What does the second 8 do?  It supposes to end $subject right after '!' which is $first_crlf, not $crlf-8.

Rickard wrote:
dealmaker wrote:

and one question in register.php:

I see this line of code in several places for writing the mail template.
$mail_subject = trim(substr($mail_tpl, 8, $first_crlf-8));

Why does it minus 8 with $first_crlf?   I don't understand.  Isn't it supposed to take the whole subject line minus 'Subject: '?

thanks.

$first_crlf contains the index of the first linebreak in the template, i.e. the one after after the subject. In order to extract the subject, we need to get $first_crlf minus 8 characters with an offset of 8.

I think the following code in include/email.php has a silly mistake.  The strtoupper should include only the substr statement, not also the os platform.  Maybe better to use Switch statement.

// Detect what linebreak we should use for the headers
    if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN'))
        $eol = "\r\n";
    else if (strtoupper(substr(PHP_OS, 0, 3) == 'MAC'))
        $eol = "\r";
    else
        $eol = "\n";

and one question in register.php:

I see this line of code in several places for writing the mail template.
$mail_subject = trim(substr($mail_tpl, 8, $first_crlf-8));

Why does it minus 8 with $first_crlf?   I don't understand.  Isn't it supposed to take the whole subject line minus 'Subject: '?

thanks.