I have a mailing list form I’m working on that is needing to have the users email subscribed to multiple email lists based on which checkboxes they select. Now to subscribe to the mailing list it’s simply emailing – list_#@domain.com
I’m curious if something like this is possible using PHP only and then send the email to different lists based on if the associated checkbox is checked?
Sure thing! Just use PHP’s mail function to send messages to the desired recipients from the email address the users specify in your webform.
One caveat, though: you may run into trouble with some mail servers and artificially-created ‘From’ headers (like those used in the mail function). For security reasons, if a message appears to be disingenuous about where it’s coming from (i.e: an unexpected sender IP), some servers will blacklist the offending IP, making it impossible to send mail from that IP to that server. You may be better-off including the subscriber’s address in the subject or body of the email, and using that data (as opposed to the From header) to add recipients to your mailing list.
EDIT: It’s also worth noting that, if the possibility exists to subscribe to many mailing lists (read: send many emails) in one execution of your mailing script, you might want to forego
mail()for something like PEAR’s mail package. The reason for this is thatmail()has to open a new SMTP socket for every message it sends, whereas packages like the one mentioned above are better suited for sending mail in batch.