I have a registration form which sends confirmation email to the new user. i also want the same email to be sent to all registered users.

I have a table containing all registered members email and i need to inform all of them of the new user.

This is what i have so far and i need help in achieving this.

<?php
//define the receiver of the email
$to = 'youraddress@example.com';
//define the subject of the email
$subject = 'Test email';
//define the message to be sent. Each line should be separated with \n
$message = "Hello World!\n\nThis is my first mail.";
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
//send the email
$mail_sent = @mail( $to, $subject, $message,$serder, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
?>

Dani AI

Generated

A few practical notes relevant to 's goal of sending a confirmation to the registrant and also notifying all existing members. Sending a mass notification directly inside the registration script is fragile: it slows or times out the signup, makes error handling harder, and hurts deliverability. and raised recipient-privacy concerns; a production-ready solution should address privacy, scale, and legal/anti-spam requirements rather than relying on a single synchronous call.

A robust pattern to implement:

  1. Record whether each member wants announcement emails (an opt-in flag) and store the new-user notification as a job in a queue table rather than sending immediately.
  2. Use a background worker or cron job to process queued jobs. The worker selects eligible recipients, personalizes the message if needed, and sends using an authenticated SMTP client or an email provider API.
  3. Send in controlled batches, log successes and failures, and implement retries with backoff. Mark delivered/bounced statuses so the system can stop emailing invalid addresses.
  4. Always include a way to unsubscribe and honor those preferences.

Deliverability and tooling: avoid relying on raw, synchronous server-side mail calls for bulk sending. Use a maintained library such as PHPMailer or a transactional provider (Mailgun, SendGrid, Amazon SES) and configure SPF/DKIM/DMARC for the sending domain to reduce spam filtering. For larger communities, offload the list management to the provider or send digest-style announcements instead of instant one-off messages.

Troubleshooting checklist: test the worker independently, log SMTP/API responses and message-IDs, watch provider rate limits, index the email column used for selection, and send a small pilot to verify headers and unsubscribe links. This approach keeps registration fast, protects member privacy, and scales in a controllable, auditable way.

Recommended Answers

All 2 Replies

You could select all User email address and create an array.

Then use the array in the BCC field (that way no one gets other peoples email address')

You can just submit the array? I'm not sure about this but you can separate the email addresses with a "," for multiple recipients.

And if they email addresses should remain as private, BCC as Squidge suggested.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.