Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to call an array within an array value + foreach
    primarykey
    data
    text
    <p>I have a contact from that suppose to send emails to different people as the dropdown option.</p> <p>The option values are defined in arrays with an array and I am battling to call the array value so the email can go to designated person. </p> <p><strong>Arrays are defined here:</strong> </p> <pre><code>if((isset($_GET['enquiry']) &amp;&amp; $_GET['enquiry']=='Locate a dealer/distributor')||(isset($_POST['enquiry']) &amp;&amp; $_POST['enquiry']=='Locate a dealer/distributor')){ $chk_Locate=TRUE; } if(isset($_GET['enquiry']) &amp;&amp; $_GET['enquiry'] == 'CC'){ $query_recipients = array(array('Complaint', 'csm@examplecompany.co.za'), array('Suggestion', 'csm@examplecompany.co.za'), array('Compliment', 'csm@examplecompany.co.za')); $enquiry = '&lt;input type="hidden" name="enquiry" id="enquiry" value="CC"&gt;'; } else{ $query_recipients = array(array('Locate a dealer/distributor', 'sales@examplecompany.co.za'), array('Technical support', 'technical@examplecompany.co.za'), array('Back orders', 'backorders@examplecompany.co.za'), array('Product enquiry', 'sales@examplecompany.co.za'), array('Catalog request', 'sales@examplecompany.co.za'), array('New customer enquiry', 'sales@examplecompany.co.za'), array('Existing customers - logon', 'dealers@examplecompany.co.za'), array('Existing customers - orders', 'weborder@examplecompany.co.za'), array('Report web problems', 'webmaster@examplecompany.co.za')); } </code></pre> <p><strong>Loop</strong></p> <pre><code>foreach($query_recipients as $key =&gt; $val){ if((isset($_POST['enquiry']) &amp;&amp; $_POST['enquiry'] == $val[0])||(isset($_GET['enquiry']) &amp;&amp; $_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') </code></pre> <p><strong>The code that calls them is:</strong></p> <pre><code>$_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 &lt;Examplecompany.orders@gmail.com&gt;'; $_POST['body'] = '&lt;p&gt;Name: ' . $_POST['name'] . '&lt;/p&gt;' . '&lt;p&gt;Surname: ' . $_POST['surname'] . '&lt;/p&gt;' . '&lt;p&gt;Company: ' . $_POST['company'] . '&lt;/p&gt;' . '&lt;p&gt;Examplecompany Account No.: ' . $_POST['accnr'] . '&lt;/p&gt;' . '&lt;p&gt;Account No. verification: ' . $cust_verify . '&lt;/p&gt;' . '&lt;p&gt;Email: ' . $_POST['email'] . '&lt;/p&gt;' . '&lt;p&gt;Tel/cell: ' . $_POST['tel'] . '&lt;/p&gt;' . $_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'; } } </code></pre> <p>This is the line I suppose to use to call them <code>$_POST['recipient_email'] = $contact_email.','.$recpt_email;</code> for now it works but it calls the last array <code>array('Report web problems', 'webmaster@examplecompany.co.za')</code> irrespective of chosen option. </p> <p>Please help, if i can find a way to call the array values I believe my form with work according to plan. </p> <p>There is a line that i dont understand</p> <pre><code>$enquiry_options .= '&lt;option&gt;'.$val[0].'&lt;/option&gt;'; $recpt_email = $val[1]; </code></pre> <p>If the val is set to <code>$Val[1]</code> the form sends email to the last email address on arrays but if set to <code>$Val[0]</code> it doesnt.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload