Asked  7 Months ago    Answers:  5   Viewed   30 times

I've seen a lot of examples using the php mail function. Some of them use rn as line break for the header, some use n.

$headers = "From: Just Men"; 
$headers .= "Reply-To:  Just me <$email>n"; 


$headers = "From: Just Mern";
$headers .= "Reply-To:  Just me <$email>rn";

which one is correct?

Sometimes I've had cases where rn is used and part of the header is interpreted by some email clients as mail text (losing these header information) - is this because rn is wrong?



The CRLF rn, should be used according to the php documentation. Also, to conform to the RFC 2822 spec lines must be delimited by the carriage return character, CR r immediately followed by the line feed, LF n.

Since rn is native to Windows platforms and n to Unix, you can use the PHP_EOL­Docs constant on Windows, which is the appropriate new line character for the platform the script is currently running on.

Wednesday, March 31, 2021
answered 7 Months ago

You cannot use HTML tags in body of mailto

According to RFC 2368, this is not possible:

The special hname "body" indicates that the associated hvalue is the body of the message. The "body" hname should contain the content for the first text/plain body part of the message. The mailto URL is primarily intended for generation of short text messages that are actually the content of automatic processing (such as "subscribe" messages for mailing lists), not general MIME bodies.

So any solution depends on HTML tags is not possible. The solution I'm suggesting is to use rn along with PHP function rawurlencode

So here's the code


    '<a class="simple-mail-link" href=""><div class="label"><div class="dashicons dashicons-admin-plugins"></div>Forward this to a friend</div></a>', 
    'My Subject',
    rawurlencode(sprintf( "Hi there, this might be interesting for you.rnThis is the link: %s.rnHave a great day!rnStefaan", get_the_permalink()))


Note: I tried the code with replacing get_the_permalink() with variable carrying


MailTo with HTML body

What is the equivalent of JavaScript's encodeURIcomponent in PHP?

Wednesday, March 31, 2021
answered 7 Months ago

Update   For a more practical and up-to-date answer, have a look at Palec’s answer.

The specified character encoding in Content-Type does only describe the character encoding of the message body but not the header. You need to use the encoded-word syntax with either the quoted-printable encoding or the Base64 encoding:

encoded-word = "=?" charset "?" encoding "?" encoded-text "?="

You can use imap_8bit for the quoted-printable encoding and base64_encode for the Base64 encoding:

"Subject: =?UTF-8?B?".base64_encode($subject)."?="
"Subject: =?UTF-8?Q?".imap_8bit($subject)."?="
Thursday, June 3, 2021
answered 5 Months ago

You can easily use line breaks in regular paste, but this is plotmath paste (actually a different function also with no 'sep' argument) and the (long) ?plotmath page specifically tells you it cannot be done. So what's the work-around? Using the plotmath function atop is one simple option:

expression(atop("Histogram of "*hat(mu), Bootstrap~samples*','~Allianz))

This will break at the comma and center the plotmath expressions. More complicated options are available.

This illustrates plotting to a graphics file. Ironically, the first effort gave me a display that did have your problem with the 'hat' (are those circumflexes?) being cut off and this shows how to increase the margins. The top margin is probably the third number so c(3,3,8,0) might suit you better:

 pdf("test.pdf") ;  par(mar=c(10,10,10,10))
 main=expression(atop("Histogram of "*hat(mu), 
                       Bootstrap~samples * ',' ~Allianz))) # don't need to restore;  this 'par' only applies to pdf()
Wednesday, June 9, 2021
answered 5 Months ago

just tested this, and it worked as expected:

$headers .= 'Cc: test@test.comrn';
$headers .= 'Bcc: test@test.comrn';

I would also suggest moving your carriage return and new line to the end of the previous entry to $headers

$headers = "From: $from_emailrnReply-To: $from_email";
$headers .= 'Cc: test@test.comrn';
$headers .= 'Bcc: test@test.comrn';
$headers .= "Return-Path: <>rn";

// add boundary string and mime type specification
$headers .= "Content-Type: multipart/mixed; boundary="PHP-mixed-".$random_hash.""";

hope that helps

Thursday, August 19, 2021
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :