Jump to content


Photo

send form contents to an email address


  • Please log in to reply
4 replies to this topic

#1 pitn

pitn
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 16 April 2006 - 11:15 AM

hello, can anyone tell me what I'm doing wrong?

<?php
$to = "mymail@hotmail.com";
$subject = "Request";
$naam = $_POST['naam'];
$telefoon = $_POST['telefoon'];
$vliegtuig = $_POST['vliegtuig'];
$datum = $_POST['datum'];
$van = $_POST['van'];
$tot = $_POST['tot'];
$vraag = $_POST['vraag']
$message = "$naam + $telefoon + $vliegtuig + $datum + $van + $tot + $vraag";
mail($to,$subject,$message);
?>

Q1: what is correct: $_POST['naam'] or ["naam"] (' or ")
Q2: $message = "$naam + $telefoon + $vliegtuig + $datum + $van + $tot + $vraag"; is + correct, or do I need to use . instead? - how can I phrase the $message better?


Tx all
Total PHP newbie

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 16 April 2006 - 12:12 PM

For Q1- Single quotes (['naam']) are right.

For Q2- You cant have your message var this way.
Here's a way you will see things and know what they are too:
$message = "naam: ".$naam." \n telefoon: ".$telefoon." \n vliegtuig: ".$vliegtuig." \n datum: ".$datum." \n van: ".$van." \n tot: ".$tot." \n vraag: ".$vraag."

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 16 April 2006 - 03:38 PM

Actually, for Q1 you can used either single or double quotes in most situations. The difference is that everything enclosed in single quote is treated as a literal, whereas items between double quotes are expanded.

The following code snippet shows the difference:
<?php
$test = 'one';
$test_array = array('$test' => 'This entry\'s index is $test', $test => 'This entry\'s index is the value of $test which is ' . $test);
echo 'This shows the value of $test_array[\'$test\']: ' . $test_array['$test'] . '<br>';
echo 'This shows the value of $test_array["$test"]: ' . $test_array["$test"] . '<br>';
echo '<pre>The array $test_array via print_r' . print_r($test_array,true) . '</pre>';
echo '<pre>The array $test_array via var_export' . var_export($test_array,true) . '</pre>';
?>

Ken

#4 pitn

pitn
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 17 April 2006 - 11:06 AM

Orio & Ken,

Tx for helping me out + taking the time to explain,

but I'm "close, but no doughnut": after pressing 'send' on the form, it returns to the original html page (which is fine); I receive the mail, with the mailsubject, BUT the mail contents are blank (?). So no $message.


<?php
$naam = $_POST['naam'];
$telefoon = $_POST['telefoon'];
$vliegtuig = $_POST['vliegtuig'];
$datum = $_POST['datum'];
$van = $_POST['van'];
$tot = $_POST['tot'];
$vraag = $_POST['vraag'];
$message = $naam;
$message .= $telefoon;
$message .= $liegtuig;
$message .= $datum;
$message .= $van;
$message .= $tot;
$message .= $vraag;
mail('mymail@hotmail.com', 'request', $message) or die("Failure!");
header ("location: Contact.htm");
?>

Any ideas?

#5 pitn

pitn
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 17 April 2006 - 11:24 AM

I put in error_reporting(E_ALL); and get the following errors:

Notice: Undefined index: naam in /customers/xxxxxx.eu/xxxxxx.eu/httpd.www/sendmail.php on line 3
....
(for every variable, so line 3 up to line9)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users