New Form2Mail (class) changes, updates

by Andy Prevost

Monday December 11 2023

The new Form2Mail aims to be far more user friendly than previous projects.

An example is how To:, From:, Cc:, and Bcc: are entered. Using To: as an example, most scripts would require you to enter that as:

$mail->RecipientName = 'John Doe';
$mail->RecipientEmail = 'john.doe@domain.com';

In my current projects, I redefined that to make it simpler (in hindsight, didn't achieve that). My efforts changed that to:

$mail->setRecipient = [ 'yourname@yourdomain.com' => 'Your Name' ];

So easy to mess up ... and it's not the fault of the user, it's my fault. There already is so much to remember in using these classes that the order of email address to user name shouldn't become a stumbling block. Matter of fact, it shouldn't even matter whether it is entered as an array or as a string.

In the new Form2Mail class, how any email address is entered doesn't matter. It can be a string, an array, or even a multi dimensional array. Some examples that will work with the new Form2Mail class are:

  • $f2m->To( 'John Doe <john.doe@domain.com>' );
  • $f2m->To( 'john.doe@domain.com' );
  • $f2m->To( [  'John Doe'=>'john.doe@domain.com', 'jane.doe@domain.com'=>'Jane Doe' ] );
  • $f2m->To( 'J. C. Cricket <jimminy.cricket@domain.com>', [  'John Doe'=>'john.doe@domain.com', 'jane.doe@domain.com'=>'Jane Doe' ] );

First example: (string) Name with tokenized email address
Second example: (string) Email address (no tokens)
Third example: (array) with different order for name/email address
Fourth example: (mixed string/array) with any order

And note the class method naming. Rather than structure that for the developer (me), I structured it to make it easier for the user. No more cryptic crap, it should be a lot easier for users. Gone is the old way of doing things (ie. $mail->SetRecipient) and in with the new ($mail->To). It's a small thing, but small things is what makes life easier.

Previous users of PHPMailer-FE used it as an Auto-Responder. I worked with many users that wanted to leverage the security of the project with the prospect of lead generation. When I revived the project as Form2Mail, that is one feature that ported over. I have expanded that in the new Form2Mail class and provided that ability as a plugin. The plugin architecture even provides access to all of the data (after processing) that is sanitized, validated, all required fields filled in. Think of it, as plugin, you can alter the Recipient (To:) and send bulk by switching the recipient (and others, if you want) into the Bcc: field. 

The possibilities are endless ... you control what the plugin does.

 

 

◀ Previous Next ▶

Post a Comment