note 111124 added to function.mail

From: Date: Thu, 17 Jan 2013 18:46:57 +0000
Subject: note 111124 added to function.mail
Groups: php.notes 
Request: Send a blank email to php-notes+get-193181@lists.php.net to get a copy of this message
<?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/. ---- Server IP: 87.124.126.49 Probable Submitter: 78.148.149.200 ---- Manual Page -- http://php.net/manual/en/function.mail.php Edit -- https://master.php.net/note/edit/111124 Del: integrated -- https://master.php.net/note/delete/111124/integrated Del: useless -- https://master.php.net/note/delete/111124/useless Del: bad code -- https://master.php.net/note/delete/111124/bad+code Del: spam -- https://master.php.net/note/delete/111124/spam Del: non-english -- https://master.php.net/note/delete/111124/non-english Del: in docs -- https://master.php.net/note/delete/111124/in+docs Del: other reasons-- https://master.php.net/note/delete/111124 Reject -- https://master.php.net/note/reject/111124 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#193181) next »