0

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?

4
  • I imagine if you have the users email address, you could use mail() or the SMTP functionality to send the request email on their behalf, they would just need their email for from. I'm guessing you're talking about something like a LISTSERV setup you're sending the requests to, as well. Commented Dec 13, 2011 at 2:10
  • thats possible. you can make that happen using javascript/jquery. Commented Dec 13, 2011 at 2:11
  • Can you simply send the email to the multiple recipients the one time? Commented Dec 13, 2011 at 2:12
  • I'm not sure I was thinking of just having a php file with something like the following: if checkbox1 is checked //send mail to this list if checkbox2 is checked //send mail to this list Would this logic work for 12 checkboxes Commented Dec 13, 2011 at 2:21

3 Answers 3

3

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 that mail() 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.

Sign up to request clarification or add additional context in comments.

Comments

0

Personally I would run this in 2 separate functions, 1 for the subscription to the email list and a second function to send the mail.

Without knowing what database or structure you're using to store the subscription data I would create a function to insert the subscription information into the database(s). The way I would likely do this (simply for flexibility of database structure) is to build an array of the subscribed mail lists and loop it with a foreach loop.

Next is the actual sending of the email, I would set up a special mail account with all of the email aliases I will send to assigned to it, I would then pipe (or poll) the mail into my system using a "CRON job", when the CRON is running I would then send the mail via SMTP through my preferred ISP or SMTP server. This again is a custom function but I have used a Pear SMTP handler in the past. There are a number of SMTP handlers out there if you do a quick Google search for "php smtp handler".

I hope this helps.

Comments

0

here is a simple form manipulation using radio buttons.

 <html>
 <head>
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
 <link rel="stylesheet" href="style.css" />
 <script type="text/javascript">
 $(document).ready(function() {
      $('input[type=submit]').click(function(e){
      e.preventDefault();   
      var id = $('input[type=radio]:checked').attr('id');
           if(id == "radio1") {
                //do an ajax call to a php file to subscribe
           } else if(id == "radio2") {
                //do an ajax call to a php file to mail
           } else {
                //do an ajax call to a php file to others
           }
      });
 });
 </script>
 </head>
 <body>
 <form>
 <input type='text' id='fname' name='fname'>
 <input type='text' id='lname' name='lname'>
 <input type='radio' id='radio1' name='lname'>
 <input type='radio' id='radio2' name='lname'>
 <input type='radio' id='radio3' name='lname'>
 <input type='submit' value='submit'>
 </form>

 </body>
 </html>

*note: i use radio button to limit user to select only one option

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.