mjfroggy
01-09-2005, 06:21 PM
Hey all,
I need help I have an order form (I am not collecting any payment info on this form) and I want to use the php mail() function. My issue is I can not make it retrieve and email all the fields I need it to. from my form.
below is my actual script
<?php
$to="my_email_here";
$from=$_POST['email'];
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$occasion=$_POST['occasion'];
$message=$_POST['message'];
$subject=$_POST['New Client Info'];
$submit=$_POST['submit'];
/* Send The Email*/
$headers = "From: $from";
if(mail($to,$subject,$fname,$lname,$occasion,$message,$headers)){
echo "Email Sent";
}else{
echo "Email Sending Failed";
}
?>
any help please so I can have my php form send all the fields I need (I have about 35 fields of data in total)
?>
Angelo
01-09-2005, 06:43 PM
Do not assign post values one by one.
<?
$msg = "";
foreach($HTTP_POST_VARS as $field=>$value) {
$msg = $msg . "$field : $value<br>\n";
}
$toAddress = "enter address";
$fromName = "Web Form";
$fromAddress = "form@mydomain.com";
$subject = "Web Form";
mail($toAddress, $subject, $msg,"From: $fromName<$fromAddress>\nMIME-Version: 1.0\nContent-Type: text/html;\n");
?>
Xenatino
01-09-2005, 06:56 PM
<?php
$to="my_email_here";
$from=$_POST['email'];
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$occasion=$_POST['occasion'];
$message=$_POST['message'];
$subject=$_POST['New Client Info'];
$submit=$_POST['submit'];
/* Send The Email*/
$headers = "From: $from";
if(mail($to,$subject,$fname,$lname,$occasion,$message,$headers)){
echo "Email Sent";
}else{
echo "Email Sending Failed";
}
?>
The space character is not valid for variables in PHP. Use _ (underscore) instead
mjfroggy
01-09-2005, 07:08 PM
ok I still need help Aras-Ferra not sure how I can use your sugestion since I am using a html form and then sending the form to the php script.
X-TechMedia
01-09-2005, 07:46 PM
<?php
$to="my_email_here";
$from = $_POST['email'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$occasion = $_POST['occasion'];
$message = $_POST['message'];
$subject = 'New Client Info';
$body = $firstname." ".$lastname."\n".$occasion."\n".$message
/* Send The Email*/
$headers = "From: $from";
if(mail($to, $subject, $body, $headers)){
echo "Email Sent";
}else{
echo "Email Sending Failed";
}
?>
Now im guessing you don't need $_POST['submit'] - im guessing its the button, also guessing that $_POST'New Client Info'] is the subject so you don't need to get it from $_POST.
Havent tetsed it, but that should work
Angelo
01-10-2005, 05:26 AM
$msg = ""; // Empy msg variable
foreach($HTTP_POST_VARS as $field=>$value) { // For every Post variable in your form
$msg = $msg . "$field : $value<br>\n"; // Add a line to the message containing the field and users value
}
Name my first file to a form.php. Than in your html file
<form method="post" action="form.php" name="form">
... here goes your form elements...
</form>
That should work.
Sheps
01-11-2005, 04:55 AM
Spaces are perfectly acceptable within a array type thingy.
Trust me... ;)
Could you do a:
print_r($_POST);
in your script somewhere, so we could see all the fields you need to collect?