Forum Moderators: coopster

Message Too Old, No Replies

Pulling my Hair Out

where am I going wrong !

         

diegomh7

3:41 pm on Aug 3, 2006 (gmt 0)

10+ Year Member



Yup im back already,

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

barns101

6:22 pm on Aug 3, 2006 (gmt 0)

10+ Year Member



Does any of it work? The problem may be that your list of recipients will have a comma at the end that should not be there. Although I can't guarantee that this is the problem, little things like that can prevent email from being sent.

dreamcatcher

8:44 pm on Aug 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep, the comma will be a problem. You are better off doing it like this:

$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

diegomh7

1:02 pm on Aug 4, 2006 (gmt 0)

10+ Year Member



thanx guys specially DC as you always seem to show me something new ive never used implode ;)

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

diegomh7

9:05 am on Aug 10, 2006 (gmt 0)

10+ Year Member



still stuck

the_nerd

10:23 am on Aug 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



instead of:

while ($i<$num){
$members = mysql_result($result,$i, "members");
$to .= "$members" . ',' ;
++$i;

try this:

while ($row = mysql_fetch_assoc($result)) {
$to .= ',' . $row['members'] ;
}

- and get rid of the comma after the initial "to".

nerd.

dreamcatcher

2:01 pm on Aug 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ive echoed $to for error handling and all i get is Array written on the screen,

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