Jump to content

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 <nate@email.com>\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...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.