0

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 Answers 2

4

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);
Sign up to request clarification or add additional context in comments.

1 Comment

See, thats why I love this place... It sometimes takes a second eye to see the problem.. Thanks so much for your answer:)
2

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 .= ...

1 Comment

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:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.