Results 1 to 10 of 10

Thread: PHP contact form mailer problem...

  1. #1
    Join Date
    Sep 2010
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation PHP contact form mailer problem...

    Hello, I am having a problem with my contact form php script.
    When I use the form and submit it, it sends an email to the right place and the body and subject of the mail is correct but the values that I typed in such as name and email do not show up. In the email it is simply:

    The website where I am implementing this mailer to test it is here:
    http://www.livingfortodayband.co.uk/basement2/contact.html

    ______________________________________…

    Name:
    Email:
    Artist:
    Subject:
    Message:

    It is empty. My current PHP code is as follows:


    PHP Code:
    <?php

    /* Subject and Email Variables */

    $emailSubject 'Basement Studio Web Enquiry';
    $webMaster 'info@basement-studios.co.uk';

    /* Gathering Data Variables */

    $nameField $_POST['name'];
    $emailField $_POST['email'];
    $artistField $_POST['artist'];
    $subjectField $_POST['subject'];
    $messageField $_POST['message'];

    $body = <<<EOD
    <br><hr><br>
    Name: 
    $name<br>
    Email: 
    $email<br>
    Artist: 
    $artist<br>
    Subject: 
    $subject<br>
    Message: 
    $message<br>
    EOD;

    $headers "From: $email\r\n";
    $headers .= "Content-type: text/html\r\n";
    $seccess mail($webMaster$emailSubject$body$headers);

    /* Results as HTML */

    $theResults = <<<EOD
    <html><body>Congrats!!</body></html>
    EOD;
    echo 
    "$theResults";

    ?>

    The HTML of the form I am using is here :

    HTML Code:
    <form action="mailer.php" method="post" enctype="multipart/form-data" id="contactform">
                <ol>
                  <li>
                    <label for="name">First Name <span class="required">*</span></label>
                    <input id="name" name="name" class="text">
                  </li>
                  <li>
                    <label for="email">Your email <span class="required">*</span></label>
                    <input id="email" name="email" class="text" />
                  </li>
                  <li>
                    <label for="artist">Band/Artist Name</label>
                    <input id="artist" name="artist" class="text">
                  </li>
                  <li>
                    <label for="subject">Subject</label>
                    <input id="subject" name="subject" class="text">
                  </li>
                  <li>
                    <label for="message">Message <span class="required">*</span></label>
                    <textarea id="message" name="message" rows="6" cols="50"></textarea>
                  </li>
                  <li>
                      <label for="valid">Seven + Four =</label>
                    <input name="valid" type="text" class="text" id="valid" onblur="MM_validateForm('element_5','','NinRange11:11');return document.MM_returnValue" size="5" maxlength="2" if="element_5" />
                  
                  </li>
                  <li class="buttons">
                    <input name="imageField" id="imageField" src="images/send.jpg" class="send" type="image">
                    <div class="clr"></div>
                  </li>
              </ol>
          </form>
    I will be so grateful if someone can help me in finding out what is wrong with my script.. also if anyone has any idea how to involve an IP address of the person who submitted the form into the body of the email that would be fantastic

    Thanks in advance

  2. #2
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    You assign the values from the POST to namefield and such but you use $name in the body. $name is not set to anything which is why it's blank, change your body variables to those of your post variables.
    PHP Code:
    $nameField $_POST['name'];
    $emailField $_POST['email'];
    $artistField $_POST['artist'];
    $subjectField $_POST['subject'];
    $messageField $_POST['message'];

    $body = <<<EOD
    <br><hr><br>
    Name: 
    $nameField<br>
    Email: 
    $emailField<br>
    Artist: 
    $artistField<br>
    Subject: 
    $subjectField<br>
    Message: 
    $messageField<br>
    EOD; 

  3. #3
    Join Date
    Sep 2010
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Some additional help

    Ahh that solved it mate. Just another question. Using the current script I get all the fields in the message and the subject.. but I have no "from" in the message title. I want to be able to see who the email is from without opening it instead of just a subject in my junk-email folder.

    THanks

  4. #4
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    Your headers for the mail should be more like this:
    PHP Code:
    $headers  'MIME-Version: 1.0' "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";
    $headers .= 'Reply-To: <the email you want>' "\r\n";
    $headers .= 'From: "What ever you want it to be like the $email" <you@yourdomain.com>' "\r\n"
    I changed some wording in the code so you know that goes in what so read that and change it accordingly. So obviously delete the headers you have now.

  5. #5
    Join Date
    Sep 2010
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hey im a little confused. If i do this then I won't get the email from the person who sent it, just from an email I type into the script... :S

    In the email header I get the email from "$email <you@yourdomain.com>".
    I need to see the persons email who actually emailed me here..

    Thanks

  6. #6
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    You mean the person that submitted the form you want the email From: to show the email they posted right? I said you had to change the info to accomadate your needs. So in your instance $email should be $emailField and then put you domain in the <> area.

  7. #7
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    I see what you are talking about, I just tried it on my site. I'll look into this.

  8. #8
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    Ok so without some more research and talking with other forum members, you could do this
    PHP Code:
    $emailSubject "$emailField - Basement Studio Web Enquiry"
    and it works. After several attempts I am not sure how to do a dynamic From: in an email, but this will at least show you the email without opening the email to see it.

  9. #9
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    PHP Code:
    <?php

    $headers 
    .= "From: $nameField <$emailField>"."\r\n";

    ?>
    However, you should really be validating your form inputs, especially before you start using them in your email headers.

  10. #10
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    Thanks Traq, that worked perfect. lcot - just change the variables in the code Traq posted to suite what you want to display when you get the email.

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
  •