473,387 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problem sending multiple emails from a mail () form

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:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. //Check if the form has been submitted.
  3. if ( isset ($_POST['submit'])) {
  4.  
  5. $problem = FALSE; 
  6.  
  7. //Check for each value.
  8.  
  9. if (empty ($_POST['email2'])) {
  10. $problem = TRUE;
  11. print '<p>Please enter your email address!</p>';
  12. }
  13. }
  14.  
  15.  
  16.  
  17.  
  18.  
  19. //Display the form.
  20. print '<form action="handle_requests.php" method="post"><p>';
  21.  
  22. print 'Email Address: <input type="text" name="email2" size="20" ' . $_POST['email2'] . '" /> <br />';
  23.  
  24. print '<input type="submit" name="submit" value="Submit Email Address" /></p>
  25. </form>';
  26.  
  27. // Complete the HTML formatting stuff.
  28. print '</div>';
  29.  
  30. ?>
  31.  
  32. Code from handle_requests page:
  33.  
  34. <html>
  35. <head>
  36. <title>Request for E-mail Updates Successful!</title>
  37. </head>
  38.  
  39. <body>
  40.  
  41. <?php // Script to handle e-mail requests for updates.
  42.  
  43. //Address error handing.
  44. ini_set ('display_errors', 1);
  45. error_reporting (E_ALL & ~E_NOTICE);
  46.  
  47. // In case register_globals is disabled.
  48. $email2 = $_POST['email2'];
  49.  
  50.  
  51.  
  52. print '<p>Your request for e-mail updates has been successful! You will be receiving a e-mail confirmation shortly.</p>';
  53.  
  54. $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']}.";
  55. mail ($_POST['email2, address@email.com'], 'Email Confirmation', $body, 'From: address@email.com');
  56.  
  57. ?>
  58. </body>
  59. </html>
Nov 17 '08 #1
5 3562
Markus
6,050 Expert 4TB
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.
Nov 17 '08 #2
Markus
6,050 Expert 4TB
I don't quite get what you're trying to do here
Expand|Select|Wrap|Line Numbers
  1. mail ($_POST['email2, address@email.com'],
but try changing it to
Expand|Select|Wrap|Line Numbers
  1. mail ("{$_POST['email2']}, address@email.com",
Mail().
Nov 17 '08 #3
nathj
938 Expert 512MB
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.
Nov 18 '08 #4
@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.
Nov 18 '08 #5
Markus
6,050 Expert 4TB
@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.
Nov 18 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Fabio Papa | last post by:
I am trying to write a windows service that sends emails to clients at specific times based on information in a sql db. Since this is done for multiple cities, I start a thread for each city and...
3
by: VB Programmer | last post by:
My company has it's own webserver, which is going to host our ASP.NET web application. We want the website to be able to send out emails. 1. What do I need on the server so that it has the...
2
by: Mr. x | last post by:
Hello, I am sending emails with Hebrew contents. When receiving emails - I cannot see the Hebrew characters (it is not outlook express configuration, because when receiving emails from friends -...
3
by: Steve Thurston | last post by:
Hi, I'm attempting to send emails for the first time using ASP.NET, so I'm hoping there's just a beginner's error going on here for me. But my emails aren't reaching their destination, and I...
3
by: VB Programmer | last post by:
I have an ASPX page where I send out emails through my mail server mail.MyDomain.com. When I send emails to MyName@MyDomain.com it sends PERFECTLY. When I try sending an email to any other address...
4
by: splicemix | last post by:
Hi all, I have recently set up a Drupal website. I am a beginner. My shared host server does not allow nobody@localhost to send emails, and prevents access to php.ini, so I spent some time...
8
by: Philippe Lang | last post by:
Hello, I need to send emails from Postgresql triggers. I was able to do it with a 'plperlu' function, that calls the 'system' perl function, that itself calls the 'mail' shell function. Is...
3
by: bcanter | last post by:
I am setting up a user request form to help our IT staff get all of the information required to setup a user account, I would like to send the form to a static address each time that it is submitted...
0
by: ramab | last post by:
hi, i'm a bit stuck here in sending emails to multiple users which i need to read from a database. With codes below, i able only to send 2 recipients. any idea how to send to multiple users? thx...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.