Please help me to set up php emails to be sent to different person

Status
Not open for further replies.

linux1880

In Runtime
Messages
455
<?php
$to = "me@headache.com";
$subject = "hi how are you";
$body = "helllo hello this is test.. this is test ........";
$headers = "From: mail@mail.co.uk\r\n" .
"X-Mailer: xxxx LONDON";
if (mail($to, $subject, $body, $headers)) {
echo("<p>Message sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>


Hello friends,

I want to send this email to different users.
I already have variables like

emails: <?=$row['email_add'] ?>
body: <?=$row['noteforstudents'] ?>

I just want different person to receive email according to the details above. Do I need to set up session or require_once for this ?

I don't know how to setup pls help
 
When you SELECT your query, use the while loop to send the Email.

Example:
PHP:
<?php
$subject = "hi how are you";
$headers = "From: mail@mail.co.uk\r\n" .
"X-Mailer: xxxx LONDON";

$sql = "SELECT * FROM mysql_table";
if ($r = mysql_query ($sql)) {
while ($row = mysql_fetch_array ($r)) {
// send the email here...it will send the email to however many people the query returns

mail($row['email_add'], $subject, $row['noteforstudents'], $headers);
}
}

?>

Hope that helps.
 
Status
Not open for further replies.
Back
Top Bottom