Log in

View Full Version : PHP script tweak!



Woody
08-08-2006, 10:30 PM
Hi, I'm back again! I have a PHP form script that isn't behaving. I have tweaked it from a previous one that Twey helped me with, but it is all working except that it is not emailing me the person's email address. It was earlier, but then I wasn't getting the message! I am all fingers and thumbs with the $"'. etc, can anyone tell me what I'm doing wrong?

The php code is:

<?php
$name = $_POST['name'];
$emailaddress = $_POST['emailaddress'];
$message = $_POST['message'];
$emailaddress = 'emailaddress:' . "\n$emailaddress\n";
$message = 'message:' . "\n$message\n";
$email = 'Neil@Fair-havens.org.uk';

mail($email, 'Fair Havens Availability Request', $message, 'From: "' . $name . '" <noreply@Fair-havens.org.uk>');
header('Location: http://www.fair-havens.org.uk/thankyou.html');
?>

I don't know PHP, I'd like to, but I'm trying to master CSS at the mo!

eeyore
08-10-2006, 09:40 PM
...so you've set up $emailaddress, your variable that contains the email address sent from the form, but then you don't use it anywhere in the mail( ) function. add the line below as line 7 of your script:

$message .= "email address: $emailaddress\n";

and all should be fine - that will add the submitted email address to the $message string, so it will be emailed as part of the message.

for dummies explanation: if you're not clear on the syntax, adding the period before the equals sign ( .= as opposed to just = ) adds to the variable rather than setting it, so in this case it adds the new line containing $emailaddress to the $message variable :)

Twey
08-10-2006, 10:04 PM
A nice touch is to make the email appear to come from the person:
mail($email, 'Fair Havens Availability Request', $message, 'From: "' . $name . '" <' . $_POST['emailaddress'] . '>');

Woody
08-11-2006, 06:19 AM
Many thanks Eeyore and Twey - that has sorted it!

One day I will get my head more around PHP (and Javascript). There is so much to learn and so little time to learn it!