Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP mail: Multiple recipients?

Tags:

php

email

I have this code:

<?php include("db.php");  $result = mysql_query("SELECT * FROM email");  while($row = mysql_fetch_array($result)) { $to = $row['address']; } $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = "[email protected]"; $headers = "From:" . $from; mail($to,$subject,$message,$headers); ?> 

In my table ("email") I have multiple addresses. (They are not comma sepparated.) How could I send my message to all of those addresses?

like image 369
Akos Avatar asked Sep 12 '11 13:09

Akos


People also ask

How can I send multiple emails at a time in PHP?

To send an email to multiple recipients in PHP, we simply separate the emails using a comma. For example, mail("[email protected], [email protected]", SUBJECT, MESSAGE); To add CC and BCC in PHP mail, we have to manually set the “Cc” and “Bcc” fields in the mail headers.

Can I send the same email to multiple recipients?

The BCC methodThe BCC (Blind Carbon Copy) method is the most common approach to send emails to multiple recipients at the same time. Emailing to multiple recipients using the BCC feature hides other recipients from the recipient, making it look like he is the sole recipient of the email.

Which is the correct syntax for sending email simple text in PHP?

PHP makes use of mail() function to send an email. This function requires three mandatory arguments that specify the recipient's email address, the subject of the the message and the actual message additionally there are other two optional parameters. mail( to, subject, message, headers, parameters );

How do you check PHP mail function is working or not?

to check if it is sending mail as intended; <? php $email = "[email protected]"; $subject = "Email Test"; $message = "this is a mail testing email function on server"; $sendMail = mail($email, $subject, $message); if($sendMail) { echo "Email Sent Successfully"; } else { echo "Mail Failed"; } ?>


1 Answers

while($row = mysql_fetch_array($result)) {     $addresses[] = $row['address']; } $to = implode(", ", $addresses); 

As specified on the mail() manual page, the "to" parameter of the function can take a comma-separated list of addresses.

like image 200
Amber Avatar answered Sep 25 '22 08:09

Amber