473,385 Members | 1,355 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,385 software developers and data experts.

PHP -Send Multiple E mails - when submit the form

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 6874
epots9
1,351 Expert 1GB
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
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 Expert 1GB
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 Expert 512MB
Use $_POST["send"] instead of $send in if else.
Jun 26 '07 #5
mwasif
802 Expert 512MB
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
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
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...
2
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...
4
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> ...
2
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,...
1
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...
6
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...
2
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...
2
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,...
0
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.