tags:

views:

75

answers:

2

Hi all,

Im trying to send an email to multiple addresses, so I wrote function that pulls the emails from the database, and separates each one with a comma, but the mailing part keeps failing. However a similar function as getmails() is working on another page, so I am really lost as to what I am doing wrong. Here is my code, any help will be appreciated.

Thanks all.

function getmails()
    {
    $id = mysql_query("SELECT * FROM subscribes ORDER BY subscribe_id DESC") or die(mysql_error());
$elements = array();
while( $activeArray=mysql_fetch_array($id) )
{
    $elements[] = $activeArray['subscribe_email'] ;
}
$main = implode(', ', $elements);
print $main;

}

 function announce() {

if( isset( $_POST['announce'])) {
    $ToEmail = getmails(); 
$EmailSubject = "".$_POST['title']."";
$mailheader .= "From: [email protected]\r\n";
$mailheader = "Reply-to:".$_POST['author']."@subdomain.domain.com\r\n";
$mailheader = "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Author: ".$_POST['author']."<br>";
$MESSAGE_BODY = "Newsletter: ".$_POST['content']."<br>";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");

  }
}
+2  A: 

I don't know whether this is your problem or not, but two of the lines that build $mailheader are discarding the previous value, because you're using $mailheader = ... rather than $mailheader .= ...

RichieHindle
Thanks. This solved the other issue i was having which was the sever email was showing as the sender, instead of the email i had specified. Thanks for your answer:)
Lea
+3  A: 

In addition to RichieHindle's obversation, The reason your mail is not working is because you are printing the results in the function as opposed to returning them. You should change this:

$main = implode(', ', $elements);
print $main;

To this:

return implode(', ', $elements);
Paolo Bergantino
See, thats why I love this place... It sometimes takes a second eye to see the problem.. Thanks so much for your answer:)
Lea