473,887 Members | 2,280 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP -Send Multiple E mails - when submit the form

30 New Member
Hi all,

I am working on the form in which you fill out the whole PHP form and e mail that details to someone. It is working fine. But now i want to send the same form to be sent to different people and user should be able choose the check boxes to whom they want to send e mail to.

I write some code simple If else conditions but i think i am making some mistakes. Because when i tried - it is not sending them e mails.

Here is my code. I have 2 files. 1 is the HTML form and second is the PHP files.

HTML FORM:----------------------I put the check boxes. - I want the user to choose the check boxes to whom user want to send E mail.
Expand|Select|Wrap|Line Numbers
  1. <td><strong>E mail Send to:</strong> </td>
  2.                <td colspan="2">
  3.                <input name="send" type="checkbox" value="Harsh">
  4.                Harsh 
  5.                <input name="send" type="checkbox" value="Abbey">
  6.                Abbey 
  7.                <input name="send" type="checkbox" value="Michelle">
  8.                Michelle               
  9.              </td>
HERE IS MY PHP CODE:--------------------------------

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $subject = "Catch of the Week- Name--".$_POST["Name"]."\n";
  4.  
  5. $message = ' Employee Firstname--'.$_POST["employee_firstname"]."\n".' Employee Lastname--'.$_POST["employee_lastname"]."\n".'Work Area--'.$_POST["work"]."\n".' Nominated For--'.$_POST["nominated"]."\n".'Comments--'.$_POST["comments"]."\n".' Name of Sender--'.$_POST["Name"]."\n".'Address--'.$_POST["Address"]."\n".'Phone Number--'.$_POST["phone_number"]."\n";
  6. $headers = 'From: webmaster@' . $_SERVER['SERVER_NAME'] . "\r\n" .
  7.    'Reply-To: webmaster@' . $_SERVER['SERVER_NAME'] . "\r\n" .
  8.    'X-Mailer: PHP/' . phpversion();
  9. if($subject)
  10. {
  11.  
  12. elseif($send == "Harsh")
  13. {
  14.  mail("hpandya@csufresno.edu", $subject, $message, $headers);
  15. }
  16.  
  17. elseif($send == "Abbey")
  18. {
  19.  mail("hnpandya2002@yahoo.com", $subject, $message, $headers);
  20. }
  21.  
  22. elseif($send == "Michelle")
  23. {
  24.  mail("", $subject, $message, $headers);
  25. }
  26.  
  27. elseif($send == "Harsh")
  28. {
  29.  mail("housingwebmaster@listserv.csufresno.edu", $subject, $message, $headers);
  30. }
  31.  
  32. echo "Thank you for nominating a staff member for our Catch of Week Drawing. Winners are drawn every Friday. You can check Housing Happenings for a list of the winners, and who nominated them. If your nomination form is complete and drawn, you win a Movie Ticket.";
  33. }
  34. else
  35. echo "failed";
  36. ?> 
[Please use CODE tags when posting source code. Thanks! --pbmods]
_______________ _______________ _______________ ___________

I have added HARSH - ABBEY and MIchelle - as check boxes but its not working when i submit. Remember it was working for only one person so when i added multiple people it is not working so the problem might be in IF Else conditions.

Thanks,
Please Help - I would Appreciate it.
Harsh
(I would never give up.....)
Jun 25 '07 #1
6 6912
epots9
1,351 Recognized Expert Top Contributor
the way elseif works is if the first one is true it doesn't check the rest. u should have single if statements for each one to get it to work.

and your starting an elseif in the body of an if statement with no beginning if
yours:
[PHP]
if(...)
{
elseif(..)
}
}
[/PHP]

should be:
[PHP]
if(...)
{
if(..)
{
}
elseif(..)
{
}
}
[/PHP]

good luck
Jun 25 '07 #2
Harshpandya
30 New Member
the way elseif works is if the first one is true it doesn't check the rest. u should have single if statements for each one to get it to work.

and your starting an elseif in the body of an if statement with no beginning if
yours:
[PHP]
if(...)
{
elseif(..)
}
}
[/PHP]

should be:
[PHP]
if(...)
{
if(..)
{
}
elseif(..)
{
}
}
[/PHP]

good luck


For some reason it it still not working - i tried changing the "if else" conditions but not working.

Please Help,

Thanks,
Harsh
Jun 26 '07 #3
epots9
1,351 Recognized Expert Top Contributor
your checkboxes have the same name (name="send"), give them different names, use different variable for each checkbox in your php code.

When u submit the form it isn't sends all the checkboxes that were checked, just the last one cuz they all have the same reference.

or u can try (not 100% sure this will work):
[PHP]$_POST["send"][0][/PHP]
or get.
Jun 26 '07 #4
mwasif
802 Recognized Expert Contributor
Use $_POST["send"] instead of $send in if else.
Jun 26 '07 #5
mwasif
802 Recognized Expert Contributor
Your script can send email to only one person. To send mail to multiple persons change the checkbox name to send[] for each checkbox.

<input name="send[]" ...

And use the below code to see if use selected the checkbox or not

if( in_array("Harsh ", $_POST["send"]) )
mail(... // send mail

if( in_array("Abbey ", $_POST["send"]) )
mail(... // send mail
Jun 26 '07 #6
Harshpandya
30 New Member
Your script can send email to only one person. To send mail to multiple persons change the checkbox name to send[] for each checkbox.

<input name="send[]" ...

And use the below code to see if use selected the checkbox or not

if( in_array("Harsh ", $_POST["send"]) )
mail(... // send mail

if( in_array("Abbey ", $_POST["send"]) )
mail(... // send mail

you guys are awesome


Thanks a Bunch
Jun 26 '07 #7

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

Similar topics

3
6054
by: Mark Michel | last post by:
Hi. I have made an html form which I would like to send by e-mail. When the recipient receives the e-mail form, I would like them to be able to fill it out and click the Submit button which will submit to an ASP page. This ASP page contains the code to submit the form data to a database. The page works fine when viewed through a browser, but the form will not submit in Outlook 2002 (I haven't tried other mail programs). Any...
2
1866
by: Matt | last post by:
The ASP page has multiple buttons, and when the user clicks different buttons, it will submit the form data to different URLs. My first approach was to use BUTTON type, and triggers javascript function to submit the form data. However, it didn't work properly and I changed to use SUBMIT type. <INPUT TYPE="BUTTON" NAME="action1" VALUE="Return to Main Search Page" onClick="action1()">
4
5813
by: Slug | last post by:
Hello, I've tried to find this answer, but can't seem to get a clear example - I'm using the following classic asp code to submit a form: <form action="default.asp" name=order method=post> What I need to do is to submit the form to multiple .asp pages, (that I want to join with frames) and I can't find a way to do it. Thanks.
2
73387
by: Terence Parker | last post by:
How does one go about submitting a form with a link - but submitting it to a new window AND to a page different to that described within the action="" option of the <form> tag? Say, for example, I have a simple form such as the following: <form method="POST" action="submit.php" name="AForm"> Name: <input type="text" name="Name" length="20"><br> Age: 15 <a href="age.php">change age</a><br> <input type="submit" name="submit"...
1
4500
by: mhawkins19 | last post by:
I have a form built and on the onclick event I validate all of the fields and then if the form is ok, on the submit event I run a javascript function to set a cookie and download a file from the current window. I have a cgi script provided by my web host to send the contents of the form through email but they only show me how to use the cgi script to send email through the submit event of the form. ie. <form name="downloadform"...
6
5011
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing for long running reports. When the processing is complete it uses crystal reports to load a template file, populate it, and then export it to a PDF. It works fine so far....
2
2881
by: weetat.yeo | last post by:
Hi all , I have a form that allow user to enter description , sometimes the description value have html special character for example %20 and etc. Inserting into the mysql database is ok , for example the description in my table is 'wt%20%20'. However . when i have href link which for instance '../edit/id=wt%20%20' .
2
5402
by: Tom_F | last post by:
To comp.databases.ms-access -- I would like to trigger an event when I close a form -- but ONLY when the data in the "RecordSource" table has been updated. I tried using the AfterUpdate event, but it fires multiple times when the form is closed ... and I only want my event to be triggered once. Could someone tell me a good way to do this? I'm using Microsoft Access 2003. Thanks very much! --Tom
0
1257
by: fperri | last post by:
Hi, I'm doing my first site in ASP.net. I have a form that has two list boxes where they can select a value in one and click a button to select and it moves it to the other listbox. I got this to work ok but once I finished the form and added my required field validators when the select button is clicked I get an error saying; Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in...
0
9957
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9799
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11173
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10877
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10434
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9593
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7988
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5810
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4239
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.