note 111124 deleted from function.mail by cmb
| From: | cmb@php.net | Date: | Sun, 22 Sep 2019 08:09:26 +0000 |
| Subject: | note 111124 deleted from function.mail by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212322@lists.php.net to get a copy of this message | ||
Note Submitter: g dot kuizinas at anuary dot com
----
<?php
**
* Function responsible for sending unicode emails.
*
* @author Gajus Kuizinas <g.kuizinas@anuary.com>
* @version 1.0.1 (2012 01 11)
*/
function mail_send($arr)
{
if (!isset($arr['to_email'], $arr['from_email'], $arr['subject'],
$arr['message'])) {
throw new HelperException('mail(); not all parameters provided.');
}
$to = empty($arr['to_name']) ? $arr['to_email'] : '"' .
mb_encode_mimeheader($arr['to_name']) . '" <' .
$arr['to_email'] . '>';
$from = empty($arr['from_name']) ? $arr['from_email'] : '"' .
mb_encode_mimeheader($arr['from_name']) . '" <' .
$arr['from_email'] . '>';
$headers = array
(
'MIME-Version: 1.0',
'Content-Type: text/html; charset="UTF-8";',
'Content-Transfer-Encoding: 7bit',
'Date: ' . date('r', $_SERVER['REQUEST_TIME']),
'Message-ID: <' . $_SERVER['REQUEST_TIME'] .
md5($_SERVER['REQUEST_TIME']) . '@' . $_SERVER['SERVER_NAME'] .
'>',
'From: ' . $from,
'Reply-To: ' . $from,
'Return-Path: ' . $from,
'X-Mailer: PHP v' . phpversion(),
'X-Originating-IP: ' . $_SERVER['SERVER_ADDR'],
);
mail($to, '=?UTF-8?B?' . base64_encode($arr['subject']) . '?=',
$arr['message'], implode("\n", $headers));
}
?>
Here is my helper function for those who are having problems properly handling UTF-8, subject, HTML,
or even the headers data. I've been using it for over a year. It works fine with simple emails.
For anything more advanced (specifically, handling attachments and multiple email versions), you
should be using an existing library like http://swiftmailer.org/.