ipwnzphp Posted July 25, 2008 Share Posted July 25, 2008 i have a mail() function inside a while loop of mysql and i need to make it only send the email 1 time for all the results like if joomla and web design is found only send 1 email for both. Link to comment https://forums.phpfreaks.com/topic/116655-mail-looping/ Share on other sites More sharing options...
ratcateme Posted July 25, 2008 Share Posted July 25, 2008 can you post some code? Scott. Link to comment https://forums.phpfreaks.com/topic/116655-mail-looping/#findComment-599799 Share on other sites More sharing options...
ipwnzphp Posted July 25, 2008 Author Share Posted July 25, 2008 $keyword = mysql_query("SELECT * FROM `sl_keywords` WHERE c_id = '$id'"); while ($keywords = mysql_fetch_array($keyword)) { $key = $keywords['keyword']; $find = strpos($Desc, $key); if ($find == true) { $service = mysql_query("SELECT * FROM sl_services WHERE service = '$key' && c_id = '$id'"); $num = mysql_num_rows($service); $services = mysql_fetch_array($service); $service = $services['service']; $price = $services['price']; $hours = $services['hours']; $option = $services['option']; $Name = "$_POST[name]"; $Email = "$_POST[email]"; $Phone = "$_POST[phone]"; $Budget = "$_POST[budget]"; $Site = "$_POST[site]"; $Work = "$_POST[work]"; $Desc = "$_POST[desc]"; $Im_client = "$_POST[im_client]"; $message = "$company Free Quote System Form" . "\n\n"; $message .= 'Name: ' . $Name . "\n"; $message .= 'Email: ' . $Email . "\n"; $message .= 'Phone: ' . $Phone . "\n"; $message .= 'Project Budget: ' . $Budget . "\n"; $message .= 'Current Site: ' . $Site . "\n"; $message .= 'Type Of Work: ' . $Work . "\n"; $message .= 'Project Desc: ' . $Desc . "\n"; $message .= 'IM Client: ' . $Im_client . "\n\n"; if ($num) { mail($email, "$company - New Quote Request", $message, "From: $Name"); } } } Link to comment https://forums.phpfreaks.com/topic/116655-mail-looping/#findComment-599800 Share on other sites More sharing options...
ratcateme Posted July 25, 2008 Share Posted July 25, 2008 why do you need the loop could you explain the loop more Scott. Link to comment https://forums.phpfreaks.com/topic/116655-mail-looping/#findComment-599802 Share on other sites More sharing options...
ipwnzphp Posted July 25, 2008 Author Share Posted July 25, 2008 so it will pull the key words to match up with the services then it sends a email to the user. Link to comment https://forums.phpfreaks.com/topic/116655-mail-looping/#findComment-599803 Share on other sites More sharing options...
ratcateme Posted July 25, 2008 Share Posted July 25, 2008 i think i understand now change if ($num) { mail($email, "$company - New Quote Request", $message, "From: $Name"); break; } that should stop the while loop and so it can only send one email Scott. Link to comment https://forums.phpfreaks.com/topic/116655-mail-looping/#findComment-599808 Share on other sites More sharing options...
ipwnzphp Posted July 25, 2008 Author Share Posted July 25, 2008 thanks works great! i had tried continue; but it didnt work but break; did! Thanks again! Link to comment https://forums.phpfreaks.com/topic/116655-mail-looping/#findComment-599813 Share on other sites More sharing options...
ipwnzphp Posted July 25, 2008 Author Share Posted July 25, 2008 o but wait.. if i have 2 services in the db it dont show both the services in the email it only shows 1 Link to comment https://forums.phpfreaks.com/topic/116655-mail-looping/#findComment-599814 Share on other sites More sharing options...
ipwnzphp Posted July 26, 2008 Author Share Posted July 26, 2008 any help? Link to comment https://forums.phpfreaks.com/topic/116655-mail-looping/#findComment-600387 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.