New Email Address Handling

<p>Both PHPMailer Pro and PHPMailer Lite released on February 10 feature new email address handling. Really that should say "contact" handling.&nbsp;</p> <p>It started with early release efforts to make adding Recipients and Sender information in an easier way. That was achieved ... the new versions of each handle it more efficiently and with more possibilities available for contact and mailing list management.</p> <p>Some basics to start:</p> <ul> <li>Names are not unique, email addresses are</li> <li>Need to accept both strings and arrays (impossible to do both, it's one or the other with possibility to concatenate)</li> </ul> <p>The first step is to "normalize" any input.</p> <p>An early decision was to parse user input into an array with the key as the email address and the value as the name portion. The reason for that is really simple. An email address is structured and unique. Name portion can vary. Take my name for example. I go by "Andy". I've been called Andre, Andrew, Adrien, and a few other variations. My legal first name is "Joseph", and I've been called by that too. I also go by my initials: "A. J. Prevost" which has been represented as "A J Prevost", "AJ Prevost" and "AJPrevost". Technically, it should be "J. A. A. Prevost". You can see the difficulty here, there is no way to "normalize" based on the name portion.</p> <p>The next early decision is based on how users can input email addresses. Here again is a staggering number of ways. Consider first strings:</p> <pre><code>$email = "Andy Prevost &lt;a1ndy@example.com&gt;,Jake And The Fatman jake@example.net,peter.pan@example.org Peter Pan";</code> </pre> <p>The first contact is in proper RFC 5322 format, the second is missing tokens, and the third is missing tokens and in reverse. There are also other possibilities: name portion only (no email address) and email address only (no name portion).</p> <p>Which brings us to another early decision: if there is no email address, the entry gets rejected.&nbsp;</p> <p>The new email address handling takes care of the string above and all variations, returning a properly formatted RFC 5322 compliant string.</p> <p>Next is dealing with input arrays. Here's an example:</p> <pre><code>$email[] = "Andy Prevost &lt;a1ndy@example.com&gt;"; $email[] = ["Andy Prevost" =&gt; "a2ndy@example.com"]; $email[] = ["a3ndy@example.com" =&gt; "Andy Prevost"]; $email[] = ["Andy Prevost"]; $email[] = ["a4ndy@example.com"]; $email[] = "Andy Prevost"; $email[] = "a5ndy@example.com"; </code> </pre> <p>A few things to notice:</p> <ul> <li>two of the array elements have the name portion only, they are not valid for sending emails</li> <li>a variety of array element structures from strings to multi-dimensional arrays</li> <li>array elements where key/value pairing is incorrect</li> <li>email addresses without tokens</li> </ul> <p>All, however, are handled properly by both PHPMailer Pro and PHPMailer Lite.</p> <p>This adds a new capability to both ... as a contact list (or mailing list) normalizing tool. You can feed in your contacts all at once through the AddRecipients method if they are all in a string or all in one array, or you can call the AddRecipients in several instances ... by example, one for strings, one for arrays. That will cause PHPMailer Pro (or PHPMailer Lite) to process each instance individually.</p> <p>Then you call invoke the Recipients method and your list is cleaned up and in one single RFC 5322 string.&nbsp;</p> <p>You could then post process that and return the cleaned up list into your database.&nbsp;</p>
Keywords: Contacts, Mailing List

Add a comment