Forum Moderators: coopster
where am i going wrong, trying to send email to multiple recips using a while loop for the mysql emails bit,
help!
$message = $_POST["txt"];
$sql = "SELECT * from members order by id";
$result = mysql_query($sql);
$num = mysql_num_rows($result);
// multiple recipients
$i = 0;
$to = 'initial@domain.co.uk' . ','; // note the comma
while ($i<$num){
$members = mysql_result($result,$i, "members");
$to .= "$members" . ',' ;
++$i;
}
// subject
$subject = 'Email from the domain E-Shot Newsletter';
// message
$message = "$message";
$message .= '<p><p>Disclaimer bit';
// 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 .= 'From: info@domain.co.uk <info@domain.co.uk>' . "\r\n";
//$headers .= 'Bcc: $to' . "\r\n";
// Mail it
echo "$to";
mail($to, $subject, $message, $headers) or die (mysql_error());
$erm = "The email has been sent successfully";
?>
I actually want the emails to be sent to BCC.
regards,
Diegomh7
$to = array();
$to[] = 'initial@domain.co.uk';
while ($i<$num){
$members = mysql_result($result,$i, "members");
$to[] = $members;
++$i;
}
Then in your mail function, implode the array:
mail(".implode(",", $to).", $subject, $message, $headers);
Also, not quite sure what the mysql_error() function is doing after your mail function?
dc
problem is it still doesnt work, the page loads without errors it just doesnt send emails out,
how do I send the emails out using Bcc, you see its for a newsletter page to be mailed out and I can;t get my head round it,
ive echoed $to for error handling and all i get is Array written on the screen,
am I just thick?
wot i got now is
<?php
// multiple recipients
$to = array();
$to[] = 'initial@domain.co.uk';
$i = 0;
while ($i<$num){
$members = mysql_result($result,$i, "members");
$to[] = $members;
++$i;
// subject
$subject = 'Email from the thgfdhgg E-Shot Newsletter';
// message
$message = "$message";
$message .= 'fgdfgdfgfdgfdgdfgf';
// 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 .= 'From: info@domain.co.uk <info@domain.co.uk>' . "\r\n";
//$headers .= 'Bcc: $Bcc' . "\r\n";
// Mail it
echo "$to";
mail(".implode(",", $to).", $subject, $message, $headers);
$erm = "The email has been sent successfully";
?>
regards,
Diegomh7
That is correct. If you wish to view the contents of an array, use print_r:
echo print_r($to);
Have you tried just using a single mail function and running it to test?
mail('youremail@you.com','Test','Test','From:You<youremail@you.com>');
dc