Jump to content

[SOLVED] E-mail problems


NathanLedet

Recommended Posts

I have a script written where people can add addresses to their address book, and then when they are sending an e-mail, they go through the list of e-mail addresses and check each e-mail they want to send the e-mail to.  When they click "Send", it sends them to another page, which dispatches the e-mail and gives confirmation.

 

The problem is if it sends to more than one person, the person that is #3 on the list will receive the message 3 times (one right under the other, not 3 different e-mails)

 

I was sent an e-mail the other day, and I was 1 of 6 people the message was sent to, and I received the message 6 times...so something funky is going on with my loop.

 

$message = $_POST['message'];
$emails = $_POST['emails'];

foreach ($emails as $e => $value){
  $str_emails .= $e . "<br />";

  $to = $e;

$subject = "You have a message";
$body .= $message . "<br /><br />";
$headers = "From: Nate <[email protected]>\r\n" . "X-Mailer: php\r\n";
$headers .= "Content-type: text/html\r\n"; 

if (mail($to, $subject, $body, $headers)) {
  echo "<p>Message sent to " . $e . "</p>";
}//end if
else {
  echo("<p>Message delivery failed...</p>");
}//end else
}//end foreach loop

Link to comment
https://forums.phpfreaks.com/topic/122875-solved-e-mail-problems/
Share on other sites

  • 1 month later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.