Sending A Message To Multiple Email Accounts
#1
Posted 09 November 2006 - 07:22 PM
#2
Posted 09 November 2006 - 07:30 PM
<?php // multiple recipients $to = 'aidan@example.com' . ', '; // note the comma $to .= 'wez@example.com'; // subject $subject = 'Birthday Reminders for August'; // message $message = ' <html> <head> <title>Birthday Reminders for August</title> </head> <body> <p>Here are the birthdays upcoming in August!</p> <table> <tr> <th>Person</th><th>Day</th><th>Month</th><th>Year</th> </tr> <tr> <td>Joe</td><td>3rd</td><td>August</td><td>1970</td> </tr> <tr> <td>Sally</td><td>17th</td><td>August</td><td>1973</td> </tr> </table> </body> </html> '; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n"; $headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n"; $headers .= 'Cc: birthdayarchive@example.com' . "\r\n"; $headers .= 'Bcc: birthdaycheck@example.com' . "\r\n"; // Mail it mail($to, $subject, $message, $headers); ?>
See how the have $to posted twice. Thats a hint! I don't want to give you the code because you won't learn anything so read this
#3
Posted 09 November 2006 - 10:44 PM
<?php
$emails = explode(', ', trim($_POST['emails'])); // You should also do any other verification with this right here, if needed, personally I would maybe use JS to peruse them before the user submits them aswell
$headers = 'From: Yoursite <you@yoursite.ext>';
foreach($emails as $e)
if(!mail($e, 'Your Subject', 'Message', $headers)) break;
?>
Edited by Mr. Matt, 10 November 2006 - 01:09 AM.
#4
Posted 11 November 2006 - 05:01 PM
#5
Posted 12 November 2006 - 12:31 AM
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0'."\r\n"
.'Content-type: text/html; charset=iso-8859-1'."\r\n";
// Additional headers
$headers .= 'To: ';
while($r=mysql_fetch_array($sql)){
$headers .= $r['name'].' <'.$r['email'].'>, ';
}
$headers = substr($headers, 0, -2)."\r\n" // Substr() to remove additional comma and space.
.'From: Birthday Reminder <birthday@example.com>'."\r\n";
// Mail it
mail($to, $subject, $message, $headers);
#6
Posted 12 November 2006 - 08:58 AM
#7
Posted 12 November 2006 - 09:41 AM
Ok so say someone inputs emails like this into the box:
email1@domain.com, email2@domain.com,email3@domain.com
You can explode it which returns an array.
$emails = explode(",",$_POST['emails']);
Now we want to mail to each email in the list so we do this:
foreach($emails as $value)
{
$to = trim($value);
// remove white space incase someone enters a space after/before comer
mail($to, $subject, $message, $headers);
}
That would mail the email to each person separately, but if you wanted it how rc posted just change the action within the loop.
foreach($emails as $value)
{
$to = trim($value);
// remove white space incase someone enters a space after/before comer
// $names = explode("@", $to);
// $headers .= $name[0].' <'.$to.'>, ';
// Use above instead to use first part of email as name as no name available.
$headers .= $to.' <'.$to.'>, ';
}
$headers = substr($headers, 0, -2)."\r\n" // Substr() to remove additional comma and space.
.'From: Birthday Reminder <birthday@example.com>'."\r\n";
// Mail it
mail($to, $subject, $message, $headers);
On another note...
Quote
Edited by Matthew., 12 November 2006 - 09:46 AM.
#8
Posted 12 November 2006 - 12:38 PM
Also, what/why did Mr. Matt edit my last post? I don't remember putting anything offensive or anything of the sort...
Edited by Demonslay, 12 November 2006 - 12:41 PM.
#9
Posted 12 November 2006 - 01:15 PM
#10
Posted 12 November 2006 - 02:33 PM
Demonslay, on Nov 12 2006, 05:38 PM, said:
Also, what/why did Mr. Matt edit my last post? I don't remember putting anything offensive or anything of the sort...
He was probably just fixing a mistake in your code
#11
Posted 12 November 2006 - 06:07 PM
Matthew., on Nov 12 2006, 07:33 PM, said:
Demonslay, on Nov 12 2006, 05:38 PM, said:
Also, what/why did Mr. Matt edit my last post? I don't remember putting anything offensive or anything of the sort...
He was probably just fixing a mistake in your code
exactly
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
