Problem sending multiple emails from a mail () form | Newbie | | Join Date: Nov 2008
Posts: 7
| |
Hi. I'm a relative newcomer to the world of php, and I keep bumping into a problem with a mail () form. I need to send an automatic email to two addresses, but I can't seem to get it to work. One email address works just fine, but I can't get the email sent to two different addresses no matter what I try. Below is my code. If someone could help me spot my errors, I'd appreciate it. Thanks! Code from actual page: - <?php
-
//Check if the form has been submitted.
-
if ( isset ($_POST['submit'])) {
-
-
$problem = FALSE;
-
-
//Check for each value.
-
-
if (empty ($_POST['email2'])) {
-
$problem = TRUE;
-
print '<p>Please enter your email address!</p>';
-
}
-
}
-
-
-
-
-
-
//Display the form.
-
print '<form action="handle_requests.php" method="post"><p>';
-
-
print 'Email Address: <input type="text" name="email2" size="20" ' . $_POST['email2'] . '" /> <br />';
-
-
print '<input type="submit" name="submit" value="Submit Email Address" /></p>
-
</form>';
-
-
// Complete the HTML formatting stuff.
-
print '</div>';
-
-
?>
-
- Code from handle_requests page:
-
-
<html>
-
<head>
-
<title>Request for E-mail Updates Successful!</title>
-
</head>
-
-
<body>
-
-
<?php // Script to handle e-mail requests for updates.
-
-
//Address error handing.
-
ini_set ('display_errors', 1);
-
error_reporting (E_ALL & ~E_NOTICE);
-
-
// In case register_globals is disabled.
-
$email2 = $_POST['email2'];
-
-
-
-
print '<p>Your request for e-mail updates has been successful! You will be receiving a e-mail confirmation shortly.</p>';
-
-
$body = "Thank you for requesting updates. Periodically, we will be sending you information about new material on our website, new publications, and upcoming events. You have registered with the following address: {$_POST['email2']}.";
-
mail ($_POST['email2, address@email.com'], 'Email Confirmation', $body, 'From: address@email.com');
-
-
?>
-
</body>
-
</html>
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,948
| | | re: Problem sending multiple emails from a mail () form
Hey there, wktarin, and welcome to the forums! Glad to have you here.
Please notice that I have formatted the code you posted in your previous post. To do this just highlight the code and then hit the '#' at the top of this editor. Doing this keeps you inside the laws of the Posting Guidelines. Give them a read.
Moderator.
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,948
| | | re: Problem sending multiple emails from a mail () form
I don't quite get what you're trying to do here - mail ($_POST['email2, address@email.com'],
but try changing it to - mail ("{$_POST['email2']}, address@email.com",
Mail().
|  | Expert | | Join Date: May 2007 Location: North Tyneside
Posts: 857
| | | re: Problem sending multiple emails from a mail () form
If you are trying to send the same email to two different addresses you need either send it to yourself and then the 2 real targets in the BCC or process the email addresses in a loop sending the email twice, in each case to only one email address.
I normally build up an array of email addresses and then loop through the array, for each element in the array call the mail() function to send the email to one recipient only. this methodology protects peoples email addresses and respects their privacy.
Cheers
nathj
PS I have an emailObject() class that I use on most of my projects, if you want I can send you a copy of this code and some usage instructions. I think we can do that within Bytes.
| | Newbie | | Join Date: Nov 2008
Posts: 7
| | | re: Problem sending multiple emails from a mail () form
@Markus: Sorry about the code gaffe. Must have missed that when I scanned the guidelines. Thanks for your response. I knew my problem had to be something ridiculously simple... But it's fixed and working now!
@nathj: The form will be sent only to the company email address and the subscriber, so the blind carbon isn't a necessity. But thank you for the reminder.
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,948
| | | re: Problem sending multiple emails from a mail () form Quote:
Originally Posted by wktarin @Markus: Sorry about the code gaffe. Must have missed that when I scanned the guidelines. Thanks for your response. I knew my problem had to be something ridiculously simple... But it's fixed and working now!
@nathj: The form will be sent only to the company email address and the subscriber, so the blind carbon isn't a necessity. But thank you for the reminder. Glad you got it working.
Good day.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,467 network members.
|