Beschreibung

Sends email. Headers and messages are converted and encoded according
to the mb_language() setting. It's a wrapper function
for mail(), so see also mail() for details.

Parameter-Liste

to

The mail addresses being sent to. Multiple
recipients may be specified by putting a comma between each
address in to.
This parameter is not automatically encoded.

subject

The subject of the mail.

message

The message of the mail.

additional_headers (optional)

String to be inserted at the end of the email header.

This is typically used to add extra headers (From, Cc, and Bcc).
Multiple extra headers should be separated with a CRLF (\r\n).
Validate parameter not to be injected unwanted headers by attackers.

Hinweis:

When sending mail, the mail must contain
a From header. This can be set with the
additional_headers parameter, or a default
can be set in php.ini.

Failing to do this will result in an error
message similar to Warning: mail(): "sendmail_from" not
set in php.ini or custom "From:" header missing.
The From header sets also
Return-Path under Windows.

Hinweis:

If messages are not received, try using a LF (\n) only.
Some Unix mail transfer agents (most notably
» qmail) replace LF by CRLF
automatically (which leads to doubling CR if CRLF is used).
This should be a last resort, as it does not comply with
» RFC 2822.

additional_parameter

additional_parameter is a MTA command line
parameter. It is useful when setting the correct Return-Path
header when using sendmail.

This parameter is escaped by escapeshellcmd() internally
to prevent command execution. escapeshellcmd() prevents
command execution, but allows to add addtional parameters. For security reason,
this parameter should be validated.

Since escapeshellcmd() is applied automatically, some characters
that are allowed as email addresses by internet RFCs cannot be used. Programs
that are required to use these characters mail() cannot be used.

The user that the webserver runs as should be added as a trusted user to the
sendmail configuration to prevent a 'X-Warning' header from being added
to the message when the envelope sender (-f) is set using this method.
For sendmail users, this file is /etc/mail/trusted-users.

User Contributed Notes 16 notes

Make sure that if you're using a form to type in the mail, that your form page has the right encoding, like if I want to send out a japanese email, by filling out a form, the form page needs this in the header:<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=SHIFT-JIS">

# self-fix...I posted "encode_mimeheader" workaround on the day before. But I found that the code depends on platforms. :(

In some platforms, hedders(after the header splited into two or more lines) will appear in the body content.The cause is that 'there are some platforms where the translation from \n to \r\n is apparently done for you'.# See the post by "leon at ietsmet dot nl" about mail function (23-Apr-2003).

Now, all you have to do is just changing the glue string from "\r\n " to "\n ".

# notice: In both code, 1 space after newline is essential (gule str is *not* only "\r\n" nor "\n").# This space is ignored only between encoded-words.

c.f. about efficiency

Thinking about efficiency, my encode_mimeheader may have to determine where to split string into lines without mb_encode_mimeheader in the determining loop. But that loop will be repeated only one or a few times and this function will be usually used against not so long string. So, this loss is not critical in most case.If you use only one encoding, you can easily check ascii or multi-byte char one by one accoding to the definition of the encoding and determining splitting point (this is far faster), but when you have to handle all encoding that is not so easy. At least, I don't want to touch. :pTo accept *any* encoding (encoding name will be passed as argument), you can use this code. This is because I post non-efficient code like this.# Though I'm not sure whether the code actually work well with all encoding...

As others say, mb_encode_mimeheader() seems to have a bug with JIS(ISO-2022-JP) encording. Token indicating start and end of multibyte char is inserted only before start of encoding and after the all.We need the tokens at start and end of *all* encoded-text.# PHP 4.3.2

So, we needs some workaround.

The post by "gordon at kanazawa-gu dot ac dot jp" seems to work well, but it doesn't. JIS nees some special tokens and base64_encode does'nt output them, so the code cannot used.

The post "RE: N03L in Japan", which simply splitting words in eash 10 chars is good enough in most case, there are some problem left. When there are some splited parts starting with ascii chars, 1 additional space will be inserted.# RFC2047 only say within 76 words, shorter is not bad.

Additionally, thought it is really rare case, when we use "=?charset?" as literal string, we have to escape them.# Some mailer can actually send this without escape and header will be broken. :(

Now, a little non-smart but maybe more accurate code is below function. I tested only with ISO-2022-JP, only in costomized phpBB2.0.5, only some cases.As far as my test this code worked well, but I'm not sure.

# $str: source text# $indent: ex. for "Subject: " header, give 9 and first line will be shorter than 76-1-9=66# $encoding: source text encoding# $mail_encoding: $str will be converted into this before base64 encode

I have to use Japanese hankaku (single byte kana in (S)JIS) in mail subject and message,so I tried the way that NO3L in Japan said, but I found there's a big problem.In that way, mb_encode_mimeheader drop escape sequence from the head of encoded string from second line.if you use long letter in subject, and if it includes multi byte string, It must crashed.Therefore, if you want to use Japanese hankaku in mail subject, you might try like this.Encoded subject letters in one line is not just 76 letters, so it is not based on RFC, but it work.

I was trying to send japanese email and had a hell of a time getting it to work. I finally stumbled across mb_send_mail() and it did everything I wanted *except* that it only send plain text emails ... sending HTML contents was impossible.

I finally whipped this up. I'm posting in case someone finds it useful.

If you have problem using mb_send_mail to send utf-8 mails, you have to know the following things (I've spent hours on the net before finding the correct php code) :

- You have to use the mb_encode_mimeheader function on the sender name and on the recipient name (on names, not on emails !).- Subject and message are automatically encoded.- Add - at least - the following header :

- Last but not least, beware of the internal encoding, which is needed by mb_encode_mimeheader function in order to encode properly. I had to set the internal encoding to UTF-8 in order to make it work properly :

First of all, don't use nl2br in newer php versions unless you WANT to write xhtml...you'll get <br /> tags.

Secondly, you should use JIS, not ISO-2022-JP as the convert TO encoding. If you use ISO... mb_encode_mimeheader seems to fail. They're the same charset anyway.

Now here's why I am really writing. I just discovered that mb_send_mail and mb_encode_mimeheader cannot support hankaku (single byte kana in (S)JIS) at all. If you are making apps for the keitai (mobile) market, this won't do. Therefore, undo your overloading on the mail function and use regular mail and convert everything yourself like this. This is what we did. It seems to work for us. Your mileage may vary.

Tested with PHP 4.2.2 on Linux: Please note that if you're using Unicode (mb_language("uni")) and you attempt to send mail with mb_send_mail(), you will need to base64_encode() the message body - mb_send_mail() doesn't do that for you. It does, however, issue the correct message headers, so you don't need to worry about that.

Also note that neither mb_language() nor mb_send_mail() is able to convert your message to UTF-8. *You* need to provide the UTF-8-encoded (and base64-encoded) message, and then mb_send_mail() will issue the correct message headers.

Here's an example of sending an UTF-8-encoded message with mb_send_mail():

If the receiving mail client supports UTF-8 properly, you will be able to send messages that contain a mix of all kinds of characters (e.g., you could send Thai, Chinese, and Danish characters in the same message). Not all mail clients support UTF-8, though. At the time of writing, some of the more popular Windows email clients - Eudora and Pegasus Mail - don't. There are a number of email clients with working support for UTF-8. These include Outlook Express, KMail, Mozilla, Netscape 6/7, Sylpheed, Evolution and others.

You may not use mb_encode_mimeheader() with mb_convert_encoding() to make subject as follows. It causes mojibake in several strings.mb_encode_mimeheader( mb_convert_encoding($strMailSubj, "JIS", "EUC-JP") )

Set mb_internal_encoding() to *subject's* encoding and call mb_encode_mimeheader.