SendMail Function - Repeats #1 and doesn't cycle

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bjstyl2
Forum Newbie
Posts: 3
Joined: Mon May 25, 2009 10:57 pm

SendMail Function - Repeats #1 and doesn't cycle

Post by bjstyl2 »

Hey I'm a newbie here, so if I am posting something unclear I apologize...

I have this function that is supposed to take all the questions that were posted for my therapist which I select and resend them to my designated person. I had 3 questions selected. It sent me the first questions approximately 250 times. Can anyone help me in fixing this to only send the question once, while cycling through the selected questions?

If I can clear anything up for you please let me know. I would like to get this fixed asap and appreciate any and all help.

Thanks,
Brian

Code: Select all

	
function sendMail()
	{
		global $mainframe,$option;
		
		$row =& JTable::getInstance('question', 'Table'); 
		$cid = JRequest::getVar('cid', array(), 'array');
		
		
		for ( $i=0;$i<count($cid);$i++ )
		{
			$id = $cid[$i]; 
			$row->load($id);
			
			
			$mailFrom 	= $mainframe->getCfg('mailfrom');
	
			$fromName 	= $mainframe->getCfg('fromname');
	
			//$notifiedEmail = explode(',',$notifiedEmail);
	
			$notifiedEmail = 'email@email.com';
				
			$subject = 'New Question posted for the Therapist';
	
	
			//echo $qId;
	
			$link2Question = JURI::root().'index.php/component/askthetherapist/?view=answer&task=edit_answer&question_id='.$id;
	
			$body = 'A question has been posted for the Therapist. To answer the question click the link and Login.<br/>'
					.'<em>The question will not be posted until an answer has been created</em><br/><br/>'
					.'<strong>Subject: </strong><a href="'.$link2Question.'">'.$row->title.'</a><br/><br/>'
					.'<strong>Question: </strong>'.$row->description.'<br/><br/>'
					.'<strong>Email: </strong>'.$row->email;
					
			$config = JComponentHelper::getParams('com_askthetherapist');
			$stremail = $config->get('email_therapist');
			$arremail = explode(';',$stremail);
			for ($i=0;$i<count($arremail);$i++)
			{
				JUtility::sendMail($mailFrom,$fromName,$arremail[$i],$subject,$body,1);	
			}
			
			
				
		}
		$mainframe->redirect('index.php?option='.$option.'&task=showquestion', 'Re-Send question to therapists successfull!');	
	}
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: SendMail Function - Repeats #1 and doesn't cycle

Post by Christopher »

It is sending the email to you multiple times because either $cid or $arremail is equal to 250.
(#10850)
Post Reply