Jump to content

Archived

This topic is now archived and is closed to further replies.

pitn

send form contents to an email address

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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:
[code]<?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>';
?>[/code]

Ken

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites

×

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.