Jump to content

Recommended Posts

Hi, Im getting better at this php lark!

ok so now I have a signup website page, all details get added to the database including an email address, all works fine.

 

now I would like a page, with a simple text box, that when you hit submit, it send the contents of the text box to all email address` in the members table, a really really simple newsletter so to speak. Its purely for my learning curve and Ill set up recapacha on it anyway.

 

but Im getting a bit lost in the code, could someone guide me please? I can grab the contents of the text box like this:

 

$letter     = $_POST['letter];

 

but how do I send to all recipients?

$recipient = ("SELECT email FROM members");

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/211182-send-email-to-all-members/
Share on other sites

Start with this:

 

http://www.phpfreaks.com/forums/index.php/topic,95441.0.html

 

And in the while loop, you need to do one of 2 things:

1) Add all users to an array or comma separated string to use in the mail() function

2) mail each recipient separately in the while loop.

 

I would send one email to all recipients, personally... and make sure you BCC them.

Start with this:

 

http://www.phpfreaks.com/forums/index.php/topic,95441.0.html

 

And in the while loop, you need to do one of 2 things:

1) Add all users to an array or comma separated string to use in the mail() function

2) mail each recipient separately in the while loop.

 

I would send one email to all recipients, personally... and make sure you BCC them.

 

thanks, I can get all the email address to display, like the link you gave, thats not the problem,

I need to do what you said, and send one email to all recipients with BCC  but I dont know how..

 

thanks again

Just bcc them in.

 

A simple example.

 

<?php

// this would come from your database.
$users = array('foo@foo.com','bar@bar.com','boo@boo.com');

$to      = 'you@youremailaddress.com';
$subject = 'subject';
$message = 'this is an example';
$headers = 'From: you@yourwebsite.com' . "\r\n" .
    'Reply-To: you@yourwebsite.com' . "\r\n" .
    'Bcc: ' . implode(', ', $users) . "\r\n";
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

 

This will send the email to you, but bcc in all your users from your database.

how would I get the emails into an array? I dont want to type them all out..?

 

if ($result = mysql_query("SELECT email FROM users")) {
  if (mysql_num_rows($result)) {
    $users = array();
    while ($row = mysql_fetch_assoc($result)) {
      $users[] = $row['email'];
    }
  }
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.