Send a PHP web form to different email addresses that are defined in arrays

I am struggling to send a PHP web form to different email addresses that are defined in arrays. The form is only sent to the last email in the arrays definition section.

Contact form code with arrays

[php] <?php
require_once(‘src/config.php’);
$VarSecurity = new VarSecurity();

$enquiry = NULL;
$chk_Locate = FALSE;

if((isset($_GET['enquiry']) && $_GET['enquiry']=='Locate a dealer/distributor')||(isset($_POST['enquiry']) && $_POST['enquiry']=='Locate a dealer/distributor')){
	$chk_Locate=TRUE;
}

if(isset($_GET['enquiry']) && $_GET['enquiry'] == 'CC'){
	$query_recipients = array(array('Complaint', '[email protected]'),
							array('Suggestion', '[email protected]'),
							array('Compliment', '[email protected]'));
	$enquiry = '<input type="hidden" name="enquiry" id="enquiry" value="CC">';
}

else{
	$query_recipients = array(array('Locate a dealer/distributor', '[email protected]'),
							array('Technical support', '[email protected]'),
							array('Back orders', '[email protected]'),
							array('Product enquiry', '[email protected]'),
							array('Catalog request', '[email protected]'),
							array('New customer enquiry', '[email protected]'),
							array('Existing customers - logon', '[email protected]'),
							array('Existing customers - orders', '[email protected]'),
							array('Report web problems', '[email protected]'));
}[/php]

Config code

[php]<?php
$db_server = 'www.examplecompany.co.za';
$db = *********
$db_username = ************
$db_password = **********

$title = 'Company ABC';
$env_repo = getenv('php_repository');
if(!empty($env_repo)){
	$classes = $env_repo;
} else {
	$classes = 'src/Classes/';
}
$pagination = array('items_per_page'=>300);
$default_page = 'Home';
$sales_email = '[email protected]';
$contact_email = '[email protected]';
$image_path = 'http://examplecompany.co.za/src/img/email/';
?>[/php]

Complete contact page code

[php]
<?php
require_once(‘src/config.php’);
$VarSecurity = new VarSecurity();

$enquiry = NULL;
$chk_Locate = FALSE;

if((isset($_GET['enquiry']) && $_GET['enquiry']=='Locate a dealer/distributor')||(isset($_POST['enquiry']) && $_POST['enquiry']=='Locate a dealer/distributor')){
	$chk_Locate=TRUE;
}

if(isset($_GET['enquiry']) && $_GET['enquiry'] == 'CC'){
	$query_recipients = array(array('Complaint', '[email protected]'),
							array('Suggestion', '[email protected]'),
							array('Compliment', '[email protected]'));
	$enquiry = '<input type="hidden" name="enquiry" id="enquiry" value="CC">';
}

else{
	$query_recipients = array(array('Locate a dealer/distributor', '[email protected]'),
							array('Technical support', '[email protected]'),
							array('Back orders', '[email protected]'),
							array('Product enquiry', '[email protected]'),
							array('Catalog request', '[email protected]'),
							array('New customer enquiry', '[email protected]'),
							array('Existing customers - logon', '[email protected]'),
							array('Existing customers - orders', '[email protected]'),
							array('Report web problems', '[email protected]'));
}

$enquiry_options = '';
$selected_notes = '';
$item = NULL;
if(isset($_GET['item'])){
	$item=$_GET['item'];
}
foreach($query_recipients as $key => $val){
	if((isset($_POST['enquiry']) && $_POST['enquiry'] == $val[0])||(isset($_GET['enquiry']) && $_GET['enquiry'] == $val[0])){
		$selected = $val[0].' : '.$item;
		if($val[0]=='Existing customers - logon'||$val[0]=='Technical support'||$val[0]=='Catalog request'||$val[0]=='Product enquiry'||$val[0]=='New customer enquiry'||$val[0]=='Existing customers - orders'||$val[0]=='Catalog request'){
			$selected_notes = '<br><p>&bull; If you are an EXISTING Examplecompany dealer please enter you Examplecompany account number so that we can correctly deal with your enquiry. Please enter your username and password for verification purposes (your login details are not sent with the enquiry). If you are already logged in you will not need to enter this information</p>
							<p>&bull; Please enter </p><br>
							<p>Examplecompany only supplies to appointed distributors, and not direct to the public.</p>
							<p>However, our showrooms are open to the public daily, where you can view our product range and get assistance with your queries.</p>';
		}elseif($val[0]=='Locate a dealer/distributor'){
			$selected_notes = '<p>&bull; Please supply your area details in the message body, as well as surrounding suburbs</p><br>';
		}
	}
	$enquiry_options .= '<option>'.$val[0].'</option>';
	$recpt_email = $val[1];
}
if(empty($selected)){
	$selected = 'Select option';
	$selected_notes = '<br><p>&bull; If you are an EXISTING Examplecompany dealer please enter you Examplecompany account number so that we can correctly deal with your enquiry. Please enter your username and password for verification purposes (your login details are not sent with the enquiry). If you are already logged in you will not need to enter this information</p><br>
							<p>Examplecompany only supplies to appointed distributors, and not direct to the public.</p>
							<p>However, our showrooms are open to the public daily, where you can view our product range and get assistance with your queries.</p>';
}

$cont_ref = NULL;
$ref_number = NULL;

if(isset($_POST['name'])){
	$VarSecurity->protectform();
	
	if ($Session->ID()==NULL){
		$query = @mysql_query('SELECT Accnr FROM WEB_Cust WHERE Uname="'.$_POST['dealer_username'].'" AND Pword="'.md5($_POST['dealer_password']).'" AND active=1 AND AXblocked!=2 LIMIT 0,1');
		$login = @mysql_num_rows($query);
		if($login==1){
			$cust_verify = 'Dealer is verified';
			$contact_email = '[email protected]';
			$Session->Logout(NULL);
		} else {
			$cust_verify = 'Dealer not verfied: username/password supplied but did not match our records.';
		}
	}elseif($Session->ID()!=NULL){
			$cust_verify = 'Dealer is verified';
			$contact_email = '[email protected]';
	}else{
		$cust_verify = 'Dealer not verfied: username/password not supplied.';
	}
	
	if(isset($_POST['enquiry']) && $_POST['enquiry'] == 'CC'){
		$done = false;
		while(!$done){
			$ref_number = 'web'.strtolower(substr(str_replace(' ', '', $_POST['company']), 0, 1)).substr(md5(microtime()), 0, 5);
			
			$unique_query = @mysql_query('SELECT * FROM web_cms_feedback WHERE ref_number="'.$ref_number.'"');
			
			if(@mysql_num_rows($unique_query) == 0){
				$done = true;
			}
		}
		
		$insert_query = @mysql_query('INSERT INTO web_cms_feedback (Web_ref, Name, Surname, Company, Accnr, Email, Tel_cell, Enquiry, Message)
								VALUES ("'.$ref_number.'", "'.$_POST['name'].'", "'.$_POST['surname'].'", "'.$_POST['company'].'", "'.$_POST['accnr'].'", "'.$_POST['email'].'", "'.$_POST['tel'].'", "'.$_POST['enquiry'].'", "'.$_POST['message'].'")');
		$insert_data = @mysql_fetch_array($insert_query);
		$cont_ref = '<br>
					<h4>Reference: '.$ref_number.'</h4>
					You will receive an automated response to your email address shortly';
	}
	
	$_POST['recipient_email'] = $contact_email.','.$recpt_email;
	if(isset($ref_number)){
		$_POST['subject'] = 'Examplecompany Group: '.$ref_number.': '.$_POST['enquiry'];
	}else{
		$_POST['subject'] = 'Examplecompany Group: '.$_POST['enquiry'];
	}
	$_POST['sender_email'] = $_POST['email'];
	$_POST['cc'] = $_POST['email'].', Examplecompany Group <[email protected]>';
	$_POST['body'] = '<p>Name: ' . $_POST['name'] . '</p>'
						. '<p>Surname: ' . $_POST['surname'] . '</p>'
						. '<p>Company: ' . $_POST['company'] . '</p>'
						. '<p>Examplecompany Account No.: ' . $_POST['accnr'] . '</p>'
						. '<p>Account No. verification: ' . $cust_verify . '</p>'
						. '<p>Email: ' . $_POST['email'] . '</p>'
						. '<p>Tel/cell: ' . $_POST['tel'] . '</p>'
						. $_POST['enquiry'] . ': ' . $_POST['message'];
						
	if(Email::Send($_POST, NULL)){
		$message = 'Your feedback has been sent'.$cont_ref;
	} else {
		$message = 'There was an error sending your feedback';
	}
}

		$Newproducts = new NewProducts();
		
		global $body;
		$body = '<div class="column-310 float-left">
					<div class="block-khaki home-highlights">
						<div class="padding-10">
							<h1 class="text-white">Welcome to Examplecompany</h1>
							<br/>
							<p>We are committed to a brighter future by creating lighting and electrical solutions which are beautiful by design and inspired by the environment. We are certain that you will find lighting and electrical products that compliment your life space and enlighten you.</p>
						</div>
					</div>
					<div class="gap-hoz-small"></div>
					<div class="block-khaki home-newprod">
						<div class="padding-10">
						
							</div>


	<table width="100%" border="0" cellspacing="0" cellpadding="10">
  <tr>
    <td align="center"><img src="src/img/contact/Examplecompany-arial-view.jpg" width="288" height="228" /></td>
  </tr>
</table>



					</div>
				</div>';
		echo $body;
?>
        <div class="gap-vert float-left"></div>
        <div class="column-630 float-left">
        	<h1 class="text-grey">Contact feedback</h1>
            <br/>
            <p class="message"><?php echo (isset($message) ? $message : NULL); ?></p>
            <br/>
            <form id="form" action="?page=contact-feedback" method="post">
                <div class="form order-form">
                	<?php if($Session->ID()==NULL && $chk_Locate==FALSE):?>
                    <div><label>Examplecompany Account No.</label><div><input type="text" name="accnr" id="accnr" class="input" maxlength="100" value="&nbsp;"/></div></div>
                    <p class="clear"></p>
                    <div><label>User name</label><div><input type="text" name="dealer_username" id="dealer_username" class="input dealer-input"/></div></div>
                    <p class="clear"></p>
                    <div><label>Password</label><div><input type="password" name="dealer_password" id="dealer_password" class="input dealer-input"/></div></div>
                    <p class="clear"></p>
                    <?php elseif($chk_Locate==FALSE):?>
                    <input type="hidden" name="accnr" id="accnr" class="input" maxlength="100" value="<?php echo $Session->ID();?>"/>
                    <?php endif?>
                    <p class="clear"></p><br />
                    <div><label>Name</label><div><input type="text" name="name" id="name" value="" class="input"/></div></div>
                    <p class="clear"></p>
                    <div><label>Surname</label><div><input type="text" name="surname" id="surname" value="" class="input"/></div></div>
                    <p class="clear"></p>
                    <div><label>Company</label><div><input type="text" name="company" id="company" value="" class="input"/></div></div>
                    <p class="clear"></p>
                    <div><label>Email</label><div><input type="text" name="email" id="email" class="input" maxlength="100"/></div></div>
                    <p class="clear"></p>
                    <div><label>Tel/cell</label><div><input type="text" name="tel" id="tel" class="input" maxlength="50"/></div></div>
                    <p class="clear"></p>
                    <div><label>Enquiry</label><div><select name="enquiry" id="enquiry" class="select"><option selected="selected"><?php echo $selected ?></option><?php echo $enquiry_options ?></select></div></div>
                    <p class="clear"></p>
                    <div><label>Message</label><div><textarea name="message" id="message" rows="5" cols="10" class="textarea"></textarea></div></div>
                </div>
                <div>
                <?php echo $selected_notes?>
                    <br/>
                    <?php echo $enquiry?>
                    <input type="submit" id="submit" value="submit" class="submit-khaki" onclick="javascript:return mail.Send();"/>
                    <p class="clear"></p>
                    <br/>
                </div>
            </form>
           <br />
          <p><input type="submit" value="Back" class="submit-khaki float-right" onclick="javascript:window.history.back();"/></p>
        </div>[/php]

The email goes to [email protected] email and the last email ([email protected]) on arrays group.

Please help.

i think the way you set up an array is like this
[php]
$query_recipients = array
(
‘Locate a dealer/distributor’ => ‘[email protected]’,
‘Technical support’ => ‘[email protected]’,
‘Back orders’ => ‘[email protected]’,
‘Product enquiry’ => ‘[email protected]’,
‘Catalog request’ => ‘[email protected]’,
‘New customer enquiry’ => ‘[email protected]’,
‘Existing customers - logon’ => ‘[email protected]’,
‘Existing customers - orders’ => ‘[email protected]’,
‘Report web problems’ => ‘[email protected]
);

//usage, this will print “[email protected]
echo $query_recipients[‘Report web problems’];
[/php]
now for example if you want to send email to [email protected] you can say $query_recipients[‘Report web problems’];

let me know if it works once you fix all your arrays

Sponsor our Newsletter | Privacy Policy | Terms of Service