Avatar of axessJosh
axessJosh

asked on 

PHP mail send once with multiple rows being inserted

I am inserting the data from an array into multiple rows of my database. That works fine.  

I also have it sending an email upon success.  Only problem is that it is sending an email for each row it is inserting. How can i just limit it to send one email if the input is successful?

 
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$count=mysql_num_rows($rsDesignated);
$acctID = $_POST['acctID'];
$amount = $_POST['amount'];
for($i=0; $i<$count; $i++){
mysql_select_db($database_con_portal_test, $con_portal_test);
  $SQL = "INSERT INTO tbldepbrk (depBrkAmnt, depBrkDate, depDesAcctID, depBrkClientID ) VALUES ('$amount[$i]' , '$_POST[date]' , '$acctID[$i]' , '$row_rsDesignated[desAcctGrpID]')";
   
   if (!mysql_query($SQL, $con_portal_test))
  {
  echo ('Error: ' . mysql_error($con_portal_test));
  }
   if ($SQL) {
  //  email confirmation to axess admins 
			   
			   
			   // send e-mail to ...
			$to = "info@thechurchbusinessguys.com";
			$to2 = $row_rs_user['usrEmail']; 
			
			// Your subject
			$subject= "Deposit Info Submitted by:" .$_SESSION['MM_Username'];  
			$subject2 = "Your Deposit information has been submitted"; 
			
			// From
			$header="Axess Client Portal Messaging";
			
			// Your message
			
			$messages = "a client has submitted a new deposit to be recorded.";
			$message2 = "Thanks for your submission.  One of our staff members will process the information shortly.  You will receive an email once the payment has been processed in our system.";
			
			
			// send email
			$sentmail = mail($to, $header, $subject, $messages);
			$sentmail2 = mail($to2, $header, $subject2, $message2);                
}
}}
?>

Open in new window


I know its sending multiple because i have it set if($SQL) and that happens each time a row is inserted.  How can i limit it?
PHP

Avatar of undefined
Last Comment
amigura
ASKER CERTIFIED SOLUTION
Avatar of amigura
amigura
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo