Forum Moderators: coopster

Message Too Old, No Replies

PHP in mail

PHP, mail

         

mac_ob1

1:39 pm on Nov 19, 2007 (gmt 0)

10+ Year Member



Hello.
I have this problem, I need to send data from a form in html to a PHP mailer file. I have checkboxes in the form and in the PHP I get the values of textboxes and radiobuttons, but not the values of the checkboxes array. Please, I'm relatively new to PHP and need some help.
I'm posting the code here:

Form:
<div id="frmchbox" align="left">
<input name="serv[]" type="checkbox" value="haircut" />Haircut<br />
<input name="serv[]" type="checkbox" value="hair extensions" />Hair Extensions<br />
<input name="serv[]" type="checkbox" value="color" />Color<br />
<input name="serv[]" type="checkbox" value="updo" />Updo<br />
<input name="serv[]" type="checkbox" value="conditioning" />Conditioning;
</div>
<div align="left">
<input name="serv[]" type="checkbox" value="blow&style" />Blowdry & Style<br />
<input name="serv[]" type="checkbox" value="highlights" />Highlights<br />
<input name="serv[]" type="checkbox" value="relaxer" />Relaxer<br/ >
<input name="serv[]" type="checkbox" value="braid style" />Braid Style<br/ >
</div>
</div>

and for the PHP:
<?
for($x==0;$x<count($serv);$x++){
$datosCheck.= $serv[$x]."\r\n";
}
$mensaje="";
$mensaje.="". "\n\n";
$mensaje.="Gender: ".$_POST['btngender']."\n";
$mensaje.="Name: ".$_POST['name']."\n";
$mensaje.="Phone: ".$_POST['phone']."\n";
$mensaje.="E-mail address: ".$_POST['mail']."\n";
$mensaje.="Services: ".$_POST[$datosCheck]."\n";
$mensaje.="Appointment: ".$_POST['schedule']."\n";
$mensaje.="Comments: ".$_POST['commentarea']."\n";
$mail="mcalderon@example.com";
$asunto="";
mail($mail,$asunto,$mensaje,"From: APPOINTMENTS<mcalderon@example.com>");
header("Location: index.html");
?>

The code may seem primitive, but I'm new as I said.
If anyone can give me some help would be great.
Thanks in advance.

[edited by: dreamcatcher at 2:01 pm (utc) on Nov. 19, 2007]
[edit reason] Use example.com, thanks. [/edit]

Habtom

1:45 pm on Nov 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A few changes:

$serv = $_POST['serv'];

for($x=0;$x<count($serv);$x++){
$datosCheck.= $serv[$x]."\r\n";
}

mac_ob1

2:28 pm on Nov 19, 2007 (gmt 0)

10+ Year Member



Thanks.
I changed the code as you said:
<?
for($x=0;$x<count($serv);$x++){
$datosCheck.= $serv[$x]."\r\n";
}
$mensaje="";
$mensaje.="". "\n\n";
$mensaje.="Gender: ".$_POST['btngender']."\n";
$mensaje.="Name: ".$_POST['name']."\n";
$mensaje.="Phone: ".$_POST['phone']."\n";
$mensaje.="E-mail address: ".$_POST['mail']."\n";
$serv = $_POST['serv'];
//$mensaje.="Services: ".$serv = $_POST[$serv]."\n";
$mensaje.="Services: ".$_POST[$datosCheck]."\n";
$mensaje.="Appointment: ".$_POST['schedule']."\n";
$mensaje.="Comments: ".$_POST['commentarea']."\n";
$mail="mcalderon@example.com";
$asunto="Royal Suite Appointment";
mail($mail,$asunto,$mensaje,"From: APPOINTMENTS<mcalderon@example.com>");
header("Location: index.html");
?>

It gives me some alerts if the line commented is not, and not receive the data yet. Where I'm I going wrong?

[edited by: eelixduppy at 2:35 pm (utc) on Nov. 19, 2007]
[edit reason] exemplified code [/edit]

ayushchd

2:59 pm on Nov 19, 2007 (gmt 0)

10+ Year Member



I think you should define $_POST['serv'] before starting the loop...

ayush

mac_ob1

3:37 pm on Nov 19, 2007 (gmt 0)

10+ Year Member



<?
$mensaje="";
$mensaje.="". "\n\n";
$mensaje.="Gender: ".$_POST['btngender']."\n";
$mensaje.="Name: ".$_POST['name']."\n";
$mensaje.="Phone: ".$_POST['phone']."\n";
$mensaje.="E-mail address: ".$_POST['mail']."\n";
$serv = $_POST['serv'];
for($x=0;$x<count($serv);$x++){
$datosCheck.= $serv[$x]."\r\n";
}
//$mensaje.="Services: ".$_POST['$datosCheck']."\n";
//$mensaje.="Services: ".$_POST['$serv']."\n";
$mensaje.="Services: ".$_POST[$datosCheck]."\n";
//$mensaje.="Services: ".$_POST[$serv]."\n";
$mensaje.="Appointment: ".$_POST['schedule']."\n";
$mensaje.="Comments: ".$_POST['commentarea']."\n";
$mail="mcalderon@example.com";
$asunto="Royal Suite Appointment";
mail($mail,$asunto, $mensaje,"From: APPOINTMENTS<mcalderon@example.com>");
header("Location: index.html");
?>

Done, tried to send the data from the checkboxes and the services field in the mail still appears empty.

ayushchd

3:58 pm on Nov 19, 2007 (gmt 0)

10+ Year Member



$mensaje.="Services: $datosCheck \n";

$datosCheck is not a POST variable...

mac_ob1

4:08 pm on Nov 19, 2007 (gmt 0)

10+ Year Member



Yes, you were right, it was my mistake.
It works perfect now.
One last favor, where do I can find a good tutorial or tutorials to learn more PHP? I mean, the "Hello World" tutorial is fine, but this kind of info is not mentioned, regardless how experienced one might be in programming php.
Thanks a lot.

ayushchd

4:11 pm on Nov 19, 2007 (gmt 0)

10+ Year Member



Well there are many places where one can learn php.

To get started, w3schools and tizag are really good.

php.net is the best once you get started.

And after all this if you have any problems, which you will surely have, this is the best place you'll ever get :)

Ayush