473,465 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with mail code

22 New Member
I am at my wits end. I have this code (posted below) with a send email button, which is in theory supposed to send just that page. The problem, that i can't resolve, is that is sends an email for each entry. So when I click the submit button i get like 20 emails. The first email has the 1 entry, 2nd has 2 entries, so on and so forth. Can anyone help resolve this, my eyes are bleeding at this point.



Expand|Select|Wrap|Line Numbers
  1. <?
  2. require("format.php");
  3. echo $format;
  4.  
  5. ?>
  6.  
  7.  
  8. </div>
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18. <div id="main"> <a name="TemplateInfo"></a>
  19. <h1></h1>
  20. <?
  21. include_once("format.php");
  22. echo $format;
  23.  
  24.  
  25. ?>
  26.  
  27. <?
  28. include_once('sql_connect.php');
  29. include_once('shared_sql.php');
  30. include_once('submittedby.php');
  31.  
  32.  
  33. $Report_Date =  date("Y-m-d H:i");
  34.  
  35.  
  36. $Title = "<H2>Weekly Action Items</H2>";
  37.  
  38. //query todo report
  39. $query1 = ("SELECT * FROM todo WHERE (Status <> 'closed') ORDER BY SubmittedBy ASC");
  40.  
  41.  
  42. $mail_form = "
  43. <form method='post' action='index.php'>
  44. <input type='hidden' name='report' value=\"$Current_Shift_Report\">
  45. <input type='text' name='email' value='xxx@xxx.com' size='55'>
  46. <input type='submit' name='submit' value='Send Report'>
  47. </form>";
  48.  
  49.  
  50.  
  51.  
  52. ////////// Start Action Items ////////////
  53.  
  54.  
  55. $Production_Control = "<H4>Data Center Action Items</h4>";
  56. While (list($Time, $Event, $Action, $TimeofLastUpdate, $Status, $SubmittedBy, $Item) = mysql_fetch_row($result1))
  57. {
  58. $Production_Control = $Production_Control. "
  59. <table rows='4' cols='4' border='1' width='650px'>
  60. <tr><td colspan='4' bgcolor='#7CFC00' valign='top'>
  61. To Do Entered On: $Time, Submitted by $SubmittedBy, Status=$Status
  62. </td></tr>
  63. <tr><td colspan='2' valign='top'>
  64. </td><td colspan='2' valign='top'>
  65.  
  66. </td></tr>
  67. <tr><td colspan='2' valign='top'>
  68. <u>Event:</u> <br />
  69. $Event
  70. </td><td colspan='2' valign='top'>
  71. <u>Action:</u> <br />
  72. $Action
  73. </td></tr>
  74. <tr><td colspan='4' valign='top'>
  75.  
  76.  
  77.  
  78.  
  79. <form action='edit_todo.php' method='post'>
  80. <input type='hidden' name='Item' value='$Item'>
  81. <input type='submit' value='Update'>
  82. </form>
  83. </td></tr></table>";
  84.  
  85.  
  86. $Current_Shift_Report = "<html><body><h2>$Title</h2>" . $Production_Control . "</body></html>";
  87.  
  88. if (isset($_POST['submit']))
  89. {
  90.  
  91.  
  92. $headers = "From:xxx@xx.com\r\n";
  93. $headers .= "Reply-To:xxx@xxx.com\r\n";
  94. $headers .= "Content-Type: text/html;\r\n charset=\"iso-8859-1\"\r\n";
  95.  
  96.  
  97.  
  98. $email = $_POST['email'];
  99. mail("$email", "$Report_Date Action Items", 
  100. $Current_Shift_Report, $headers);
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110. if(!mail)
  111. {
  112. echo "Your submission failed, please try again later";
  113. }
  114.  
  115.  
  116.  
  117.  
  118. }
  119. }
  120.  
  121.  
  122.  
  123. // Print Content //
  124. echo "<div id='content'>"
  125. .$mail_form
  126. .$todoHead
  127. .$Production_Control
  128.  
  129. ."</div>";
  130.  
  131.  
  132.  
  133. echo "";
  134.  
  135. ?>
  136.  
Dec 17 '08 #1
4 1351
dumm
10 New Member
Your code to send the email is in your while loop.
So while you are fetching the data from your mysql query, you are sending an email every time you fetch a row.
Dec 17 '08 #2
matthewroth
22 New Member
Oh thank you lord. All fixed. I knew fresh eyes would fix the issue, thanks again
Dec 17 '08 #3
matthewroth
22 New Member
At least I got it down to just 2 emails. Can someone point out the error that is giving me multiple emails this time

Expand|Select|Wrap|Line Numbers
  1. <?
  2. require("format.php");
  3. echo $format;
  4.  
  5. ?>
  6.  
  7.  
  8. </div>
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18. <div id="main"> <a name="TemplateInfo"></a>
  19. <h1></h1>
  20. <?
  21. include_once("format.php");
  22. echo $format;
  23.  
  24.  
  25. ?>
  26.  
  27. <?
  28. include_once('sql_connect.php');
  29. include_once('shared_sql.php');
  30. include_once('submittedby.php');
  31.  
  32.  
  33. //query todo report
  34. $query1 = ("SELECT * FROM todo WHERE (Status <> 'closed') ORDER BY SubmittedBy ASC");
  35.  
  36.  
  37. ////////// Start Action Items ////////////
  38.  
  39.  
  40. $Production_Control = "<H4>Data Center Action Items</h4>";
  41. While (list($Time, $Event, $Action, $TimeofLastUpdate, $Status, $SubmittedBy, $Item) = mysql_fetch_row($result1))
  42. {
  43. $Production_Control = $Production_Control. "
  44. <table rows='4' cols='4' border='1' width='650px'>
  45. <tr><td colspan='4' bgcolor='#7CFC00' valign='top'>
  46. To Do Entered On: $Time, Submitted by $SubmittedBy, Status=$Status
  47. </td></tr>
  48. <tr><td colspan='2' valign='top'>
  49. </td><td colspan='2' valign='top'>
  50.  
  51. </td></tr>
  52. <tr><td colspan='2' valign='top'>
  53. <u>Event:</u> <br />
  54. $Event
  55. </td><td colspan='2' valign='top'>
  56. <u>Action:</u> <br />
  57. $Action
  58. </td></tr>
  59. <tr><td colspan='4' valign='top'>
  60.  
  61.  
  62. <form action='edit_todo.php' method='post'>
  63. <input type='hidden' name='Item' value='$Item'>
  64. <input type='submit' value='Update'>
  65. </form>
  66. </td></tr></table>";
  67.  
  68. $mail_form = "
  69. <form method='post' action='index.php'>
  70. <input type='hidden' name='report' value=\"$Current_Shift_Report\">
  71. <input type='text' name='email' value='xxx@xxx.com' size='55'>
  72. <input type='submit' name='submit' value='Send Report'>
  73. </form>";
  74.  
  75.  
  76. }
  77.  
  78. // Print Content //
  79. echo "<div id='content'>"
  80. .$Production_Control
  81. .$mail_form
  82. ."</div>";
  83.  
  84.  
  85. echo "</body></html>";
  86.  
  87.  
  88.  
  89. ?>
  90.  
  91. <?
  92. $Report_Date =  date("Y-m-d H:i");
  93. $Title = "<H2>Weekly Action Items</H2>";
  94.  
  95.  
  96.  
  97.  
  98.  
  99. $Current_Shift_Report = "<html><body><h2>$Title</h2>". $Production_Control ."</body></html>";
  100.  
  101.  
  102. if (isset($_POST['submit']))
  103. {
  104.  
  105.  
  106.  
  107.  
  108. $headers = "From:xxx@xxx.com\r\n";
  109. $headers .= "Reply-To:xxx@xxx.com\r\n";
  110. $headers .= "Content-Type: text/html;\r\n charset=\"iso-8859-1\"\r\n";
  111.  
  112.  
  113.  
  114. $email = $_POST['email'];
  115. mail("$email", "$Report_Date Action Items", 
  116. $Current_Shift_Report, $headers);
  117.  
  118.  
  119. if(!mail)
  120. {
  121. echo "Your submission failed, please try again later";
  122. }
  123.  
  124. }
  125.  
  126.  
  127. ?>
  128.  
Dec 18 '08 #4
dumm
10 New Member
Expand|Select|Wrap|Line Numbers
  1. $email = $_POST['email'];
  2.  mail("$email", "$Report_Date Action Items", 
  3.  $Current_Shift_Report, $headers);
  4.  
  5.  
  6.  if(!mail)
  7.  {
  8.  echo "Your submission failed, please try again later";
  9.  }
  10.  


Try:


Expand|Select|Wrap|Line Numbers
  1. $email = $_POST['email'];
  2.  $sendmail = mail("$email", "$Report_Date Action Items", 
  3.  $Current_Shift_Report, $headers);
  4.  
  5.  
  6.  if(!$sendmail)
  7.  {
  8.  echo "Your submission failed, please try again later";
  9.  }
  10.  
Dec 18 '08 #5

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

Similar topics

0
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ...
6
by: dmiller23462 | last post by:
Here is the code, it's not complete of course....I've been inserting lines as I go to pinpoint the issue.....I understand that the error message I'm getting (#185 Missing Default Property) is...
9
by: YZK | last post by:
Hello. I'm not a Web developer, just a user, and I think I may have somehow messed myself up majorly. I'm not quite sure how. Right now, javascript used by websites I go to either does not work at...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
7
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that...
3
by: Sandy | last post by:
Hello - I am attempting to email error messages to myself in the event of an error. I am using the following code: Dim mail as New MailMessage() Dim ErrorMessage = "The error description is...
11
by: shror | last post by:
Hi every body, Please I need your help solving my php mail() function problem that the code is appearing in the view source and I dont know whats the problem where I am using another page tto test...
5
by: ibid | last post by:
hi every one just wondering if anyone could help sorry if i seem abit dumb but im a newbie to it all ive got to asign a mail program on my auction site in the config.pl files (i think this is the...
1
by: maxxxxel | last post by:
Hi Can anyone help me with some asp code , I changed the code to use CDO.message instead of the old cdont.sys to send mail from a ASP webpage which works fine. Our problem is that when we send...
3
by: jambonjamasb | last post by:
Hi I have two tables: email_tbl Data_table Data table is is used to create a Form Data_form
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
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...
1
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...
0
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...
0
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.