Results 1 to 4 of 4

Thread: PHP script tweak!

  1. #1
    Join Date
    Jun 2006
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question PHP script tweak!

    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!

  2. #2
    Join Date
    Aug 2006
    Location
    France
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ...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

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    A nice touch is to make the email appear to come from the person:
    Code:
    mail($email, 'Fair Havens Availability Request', $message, 'From: "' . $name . '" <' . $_POST['emailaddress'] . '>');
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Jun 2006
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •