Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:73429 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 53899 invoked from network); 25 Mar 2014 17:52:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Mar 2014 17:52:03 -0000 Authentication-Results: pb1.pair.com smtp.mail=garyamort@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=garyamort@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.170 as permitted sender) X-PHP-List-Original-Sender: garyamort@gmail.com X-Host-Fingerprint: 209.85.128.170 mail-ve0-f170.google.com Received: from [209.85.128.170] ([209.85.128.170:34897] helo=mail-ve0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 07/24-29088-E32C1335 for ; Tue, 25 Mar 2014 12:51:58 -0500 Received: by mail-ve0-f170.google.com with SMTP id pa12so983818veb.29 for ; Tue, 25 Mar 2014 10:51:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=+DxYESByVtx5R+5lAqiMgpc8aaJ3kkCb5xUBSmcQ2AQ=; b=f/wHL/1Vo7DheurC16CT9Iury5XJRF9dKDvIV2ib4ZsoV8mZnHU+5USVIwwohnEyx1 auDbpln4puCRM/yLKrrGt68wyg4nrXM0MCkp/hMvKMrq8a8MNQ9APdQ3u1UZ3qCopaik RxUGKW54WJZzXjB2w9CuU3Sqw8VeZxqkT6eCW5FHNpbU8bkID6AaMQFtnejqTFK5ifMN jlygdiQPJ5MrE8r96TE05Y0glGrS2OFVjDMeiLMNQJWIGNkzE1azYYQKZ2DwS8P4Jmwk zs+xhmAPCHJIvGIIXlZ3roOp0UDxoXm4V3F57q3G/vXH3ygRRvXhPcDyF1vVxMd4VLdQ kLgA== X-Received: by 10.220.104.210 with SMTP id q18mr47314152vco.9.1395769915784; Tue, 25 Mar 2014 10:51:55 -0700 (PDT) Received: from ?IPv6:2604:2000:1118:4036:62a4:4cff:fea8:603d? ([2604:2000:1118:4036:62a4:4cff:fea8:603d]) by mx.google.com with ESMTPSA id d8sm20324883vek.11.2014.03.25.10.51.54 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 10:51:55 -0700 (PDT) Message-ID: <5331C238.6050409@gmail.com> Date: Tue, 25 Mar 2014 13:51:52 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: Stas Malyshev , "internals@lists.php.net" References: <5330E319.5060302@gmail.com> <5330F2B2.1030201@sugarcrm.com> In-Reply-To: <5330F2B2.1030201@sugarcrm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Proposal: Mail Handling, feedback requested From: garyamort@gmail.com (Gary Mort) On 03/24/2014 11:06 PM, Stas Malyshev wrote: > Hi! > >> Current e-mail handling in PHP is dreadful. Almost every framework >> implements it's own email handling class in order to make sending e-mail >> reliable, easy to configure, and to implement multiple mail schemes. > > That is probably because sending mail involves more than just passing a > stream of bytes to SMTP server. There's MIME, encodings, headers, etc. > which all need to be taken care of. There's email server configurations. > There's error handling. > Sending mail is just passing a stream of bytes to a stream. That stream could be an SMTP server, it can be an executable program, or it can be a file. Generating proper Mime attachments, encoding, headers, etc deal with e-mail formatting and will affect how mail is displayed- but their impact on mail delivery should be non-existant! See RFC2822, https://tools.ietf.org/html/rfc2822#section-3.5 The only elements you need for e-mail delivery is a recipient and a message. Subject, from, headers, etc are all optional. Note 'should be' - in practice they MAY have an impact depending on to what MDA[Mail Delivery Agent] PHP is submitting the message. The MDA /may/ extrapolate missing information from the header fields and it /may/ modify the header fields. This message is a good example, if you are receiving individual list messages you will have 2 copies[the one I sent to the list and the one I sent to you] - you can compare the headers and see how the mail list[which itself is an MDA] modified the headers from the originals. >> class MailMessage { >> >> /* Properties */ >> $private array $recipients; >> $private string $sender; >> $private string $subject; >> $private string $body; >> $private string $header; > > What is "header"? If it's a content of whole header, then a) it already > includes all previous fields except "body" and b) you'd still need a > user class to actually make any use of it > Does it mean if I set $header it would automatically set all the rest of > the fields contained there? Does it mean if I set $subject $header would > automatically be updated? Good point, there are a couple of extra parameters/properties: $recipients['cc'], and $recipients['bcc']. Everything else maps directly to the current mail function. Those 2 properties are mapped implicitly for the mail function today. bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] ) CC and BCC today must be placed manually in $additional_parameters today and under this proposal, you can still do that when using the mail() function. If, however you decide to use the MailMessage class, you have the option of specifying them directly through setRecipients(). Beyond that, everything functions in the same manner as it does today. IE $header has no direct relationship to $subject, $to, or $from. Frameworks are encouraged to subclass MailMessage and extend it's functionality to suite their requirements - ie if they to synchronize the header property with the recipients/from/subject properties they are free to do so - there is no rule/standard saying they cannot. $mail = new MailMessage(null, $subject, $body, $headers, $from, $parameters); $mail->setRecipients($recipients); $mail->sendBatch(); Would be equivalent to: // Calculate the message TO recipients $to = implode(','.$recipients['to']); // Update parameters with optional cc recipients $cc = implode(',',$recipients['cc']); $parameters .= (!empty($cc)) ? ' -c '.$cc : ''; // Update parameters with optional bcc recipients $bcc = implode(',',$recipients['bcc']); $parameters .= (!empty($cc)) ? ' -b '.$bcc : ''; mail($to, $subject, $body, $headers, $parameters); Which incidentally, could be emulated using exec as follows: /* A message consists of a header followed by an optional body. Must be seperated by a CRLF */ $message = $headers ? $headers .CRLF . $body : $body; // Mail command $mailcommand = 'mail'; // Add subject $mailcommand .= ' -s '.$subject; // Add extra parameters mailcommand .= '$parameters'; // Add to recipients $mailcommand .= ' '.$to; // Add the messsage $mailcommand .= ' < '.escapeshellarg($message); // Send the message exec($mailcommand);