Jump to content

PHP Array Help Please!


napsburypark

Recommended Posts

Hi Folks.

 

A quick question.

I am trying out the fcbkcomplete script which will be great on a new school website I am working on however when it sends the form field it sends it as select2[]

so if I were using the GET method I  see in the address bar

 

submit.php?select2[]=test@test.com

 

however when i try and capture the select2[] php just says 'array' 

 

Any ideas?

Thank you

Link to comment
Share on other sites

actually I now have another little problem.

 

I need the form to send via PHPMAIL - I am using the following.

 

<?php

$to = $arr = $_GET['select2']; foreach( $arr as $a){ echo $a;};

$subject = $_REQUEST['Subject'] ;

$message = "This is an online form enquiry sent from the website.

 

Your Name:

".$_REQUEST['parent']."

 

Your Telephone:

".$_REQUEST['telephone']."

 

Your Message:

".$_REQUEST['message']."

 

 

This email was automatically generated. Thank You";

$from = $_REQUEST['email'] ;

$headers = "From: $from";

mail($to,$subject,$message,$headers);

echo "";

?>

 

but i get the following error now:

Warning: mail() expects parameter 1 to be string, array given in /home/marlb/public_html/About/form/submit1.php on line 33

 

Any ideas?

Link to comment
Share on other sites

as prometheos said, $arr, or $_GET['select2[]'], both of these are array

if u dont know what is array, read http://php.net/manual/en/language.types.array.php

so, u access $arr[0] or $arr[0]

$arr= $_GET['select2[]'];

$to=$arr[0]; 

NOT the following

$to = $arr  <<< WRONG!!!!!!!!!!!!!!!!!!!!!!!!!!!!

 

in the wrong case, u get this

$arr= array('something', 'something1', 'something');

 

in the right case

u get $arr='something';

Link to comment
Share on other sites

Okay got it. Thank you I have this working now.

 

I have just one more query.

 

If the form submits more than one email address it will post the following:

 

submit.php?select2[]=user1@email.com&select2[]=user2@email.com

 

however PHPMail just sees this as to: user1@email.comuser2@email.com

 

how can I make the following code break those two email addresses up?

 

<?php
$arr = $_REQUEST['select2'];
foreach( $arr as $a){
}
?>								
<?php
$to=$arr[0]; 
$subject = $_REQUEST['Subject'] ;
$message = "This is an online form enquiry sent from the Website. The details of which are below.

Your Name:
".$_REQUEST['parent']."

Your Telephone:
".$_REQUEST['telephone']."

Your Message:
".$_REQUEST['message']."


This email was automatically generated. Thank You";
$from = $_REQUEST['email'] ;
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "";
?>

 

I know I am asking a lot but I am new to PHP and just need to get this PHP element working. Thank you in advance for all your help.

 

Link to comment
Share on other sites

actually I now have another little problem.

 

I need the form to send via PHPMAIL - I am using the following.

 

<?php

$to = $arr = $_GET['select2']; foreach( $arr as $a){ echo $a;};

$subject = $_REQUEST['Subject'] ;

$message = "This is an online form enquiry sent from the website.

 

Your Name:

".$_REQUEST['parent']."

 

Your Telephone:

".$_REQUEST['telephone']."

 

Your Message:

".$_REQUEST['message']."

 

 

This email was automatically generated. Thank You";

$from = $_REQUEST['email'] ;

$headers = "From: $from";

mail($to,$subject,$message,$headers);

echo "";

?>

 

but i get the following error now:

Warning: mail() expects parameter 1 to be string, array given in /home/marlb/public_html/About/form/submit1.php on line 33

 

Any ideas?

 

This code is find all you need to change is:

 

mail($to, ..

 

to

 

mail(implode(',', $to), ..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.