mass mailing

Ask about a PHP problem here.
Post Reply
umamaheswararao
Posts: 1
Joined: Mon Jul 23, 2012 8:07 am

mass mailing

Post by umamaheswararao »

how can i restrict the automatic mailing to all users who subscribed the email alerts.my question is when new user is subscribing the automatic mail is sent to all users who are already in mysql db..how can i stop to mailing to already registered users
User avatar
Helx
Posts: 350
Joined: Thu May 17, 2012 6:45 am
Location: Auckland, New Zealand

Re: mass mailing

Post by Helx »

Check if the user has clicked the submit button, then set up a mail(); thingy.
if(isset($_POST["submit"])){

    // Do the actual subscription first

    $to = $_POST["email"];
    $headers = 'From: webmaster@example.com' . "\r\n" .
    $subject = "You have subscribed to us!";
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
    $message = "You're now subscribed to our newsletter!";

    mail($to, $subject, $message, $headers);
}
Depending on what you're doing, you may want to send the latest newsletter to the new subscriber. Simply change the $message variable to whatever you want. Maybe a database thing.

You'll want to look more deeply into checking if the user is already subscribed before sending the 'success' email, and maybe add a touch more security to everything. Like maybe a captcha or anti-robot question.

Oh, and you may want to change the subject... I'm pretty sure that'll end up in spam XD
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: mass mailing

Post by jacek »

umamaheswararao wrote:how can i restrict the automatic mailing to all users who subscribed the email alerts.my question is when new user is subscribing the automatic mail is sent to all users who are already in mysql db..how can i stop to mailing to already registered users
Depends how you know they have registered ? If there name is in another table check for that, if there is a column that gets set to 1 check for that. No way to answer fully unless you give a bit more information. ;)
Image
User avatar
Helx
Posts: 350
Joined: Thu May 17, 2012 6:45 am
Location: Auckland, New Zealand

Re: mass mailing

Post by Helx »

umamaheswararao wrote:to all users who subscribed the email alerts.
Wow.. I completely read that wrong :/
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: mass mailing

Post by jacek »

abcedea wrote:Wow.. I completely read that wrong :/
Yep :lol:
Image
Post Reply