www.webdeveloper.com
Results 1 to 9 of 9

Thread: Problem with PHP Script need help urgently.

  1. #1
    Join Date
    Feb 2013
    Posts
    9

    Problem with PHP Script need help urgently.

    Ive just designed my first contact form for my website so people can sign up to sell tickets to the event but when i click submit on the form it goes to a new page and says theResults all its meant to do is have a little box pop under neath submit sayin the success message. I am also receiving a email from the contact box but all it has in the email is the headers without any of the information.

    I don't understand why this is happening i will post the php code if anybody could edit it so its right or tell me what i need to do to fix it this will be great.

    PHP Code:
    <?php

    /* Subject and Email Variables */

        
    $emailSubject 'Insomnia All Ages Promoters';
        
    $webMaster 'aaron@superbsoundentertainment.com';
        
    /* Gathering Data Variables */

        
    $nameField $_POST['name'];    
        
    $emailField $_POST['email'];
        
    $mobileField $_POST['mobile'];
        
    $schoolField $_POST['school'];
        
    $dobField $_POST['dob'];
        
    $addressField $_POST['address'];
        
    $whyField $_POST['why'];
        
        
    $body = <<<EOD
    <br><hr><br>
    Name: 
    $name <br>
    Email: 
    $email <br>
    Mobile: 
    $mobile <br>
    School: 
    $school <br>
    DOB: 
    $dob <br>
    Address: 
    $address <br>
    Why: 
    $why <br>
    EOD;

        
    $headers "From: $email\r\n";
        
    $headers .= "Content-type: text/html\r\n";
        
    $success mail($webMaster$emailSubject$body$headers);
        
    /* Results rendered as HTML */

        
    $theResults = <<<EOD
    <html>
    <head>
    <title>JakesWorks - travel made easy-Homepage</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    <!--
    body {
        background-color: #f1f1f1;
        font-family: Verdana, Arial, Helvetica, sans-serif;
        font-size: 12px;
        font-style: normal;
        line-height: normal;
        font-weight: normal;
        color: #666666;
        text-decoration: none;
    }
    -->
    </style>
    </head>

    <div>
      <div align="left">Thank you for signing up! We will be in contact with you very soon! Kind regards the team at Superb Sound Entertainment</div>
    </div>
    </body>
    </html>
    EOD;
    echo 
    "theResults";         

                
    ?>
    Regards
    Aaron

  2. #2
    Join Date
    Aug 2012
    Posts
    155
    I can help you but need to see your form as well please

  3. #3
    Join Date
    Feb 2013
    Posts
    9
    here is the code for the form

    <form id="form1" name="form1" method="post" action="contactformprocess.php">
    <table width="534" border="0" align="center" cellpadding="6">
    <tr>
    <td width="164">Your Name (required)
    <input name="name" type="text" id="name" onblur="MM_validateForm('name','','R');return document.MM_returnValue" maxlength="255" /></td>
    <td width="179"><label> Your Email (required)
    <input name="email" type="text" id="email" onblur="MM_validateForm('email','','RisEmail');return document.MM_returnValue" maxlength="255" />
    </label>
    <br /></td>
    <td width="147">Your Mobile
    <input name="mobile" type="text" id="mobile" onblur="MM_validateForm('mobile','','RisNum');return document.MM_returnValue" />
    <br /></td>
    </tr>
    <tr>
    <td><label>Your School</label>
    <input type="text" name="school" id="school" /></td>
    <td><label>Your Date of Birth</label>
    <input type="text" name="dob" id="dob" />
    <br /></td>
    <td><label>Your Home Address</label>
    <input type="text" name="address" id="address" /></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><label>Why do you want to become a Promoter</label>
    <br />
    <textarea name="why" id="why"></textarea>
    <br /></td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td><br /></td>
    <td><p>
    <input name="submit" type="submit" id="submit" onclick="MM_validateForm('name','','R','email','','RisEmail','mobile','','RisNum');return document.MM_returnValue" value="Submit" />
    </p>
    <p>&nbsp;</p></td>
    <td>&nbsp;</td>
    </tr>
    </table>
    <p><br />
    </p>
    </form>

    hope you can help.

  4. #4
    Join Date
    Aug 2012
    Posts
    155
    Actually, now I look back at your form and email code I can see why you aren't getting any content - you are using variables in the body of your message but not defining them or allocating values (the variable names above where you assign the posted data are different). You code can also be simplified a lot:
    PHP Code:
    <?php 

    /* Subject and Email Variables */ 

        
    $emailSubject 'Insomnia All Ages Promoters'
        
    $webMaster 'aaron@superbsoundentertainment.com'
         
    /* Gathering Data Variables */ 

        
    $name $_POST['name'];     
        
    $email $_POST['email']; 
        
    $mobile $_POST['mobile']; 
        
    $school $_POST['school']; 
        
    $dob $_POST['dob']; 
        
    $address $_POST['address']; 
        
    $why $_POST['why']; 
         
        
    $body '<br><hr><br>';
        
    $body .= 'Name: {$name}<br>'
        
    $body .= 'Email: {$email}<br>';
        
    $body .= 'Mobile: {$mobile}<br>';
        
    $body .= 'School: {$school}<br>';
        
    $body .= 'DOB: {$dob}<br>'
        
    $body .= 'Address: {$address}<br>';
        
    $body .= 'Why: {$why}<br>';

        
    $headers "From: $email\r\n"
        
    $headers .= "Content-type: text/html\r\n"
        
    $success mail($webMaster$emailSubject$body$headers);
    I am not sure if the form action (contactformprocess.php) is sending to a new page or the same page but if you want the success message to appear on the same page then the code above needs to be at the top of the page with your form and then underneath the Submit button on the form you would put:
    Code:
    <?php if ($success) { ?>
    <div> 
      <div align="left">Thank you for signing up! We will be in contact with you very soon! Kind regards the team at Superb Sound Entertainment</div>
    </div> 
    <?php } ?>

  5. #5
    Join Date
    Feb 2013
    Posts
    9
    I'm not to sure what you mean by this I am not sure if the form action (contactformprocess.php) is sending to a new page or the same page but if you want the success message to appear on the same page then the code above needs to be at the top of the page with your form and then underneath the Submit button on the form you would put: could you please explain it a little more.

  6. #6
    Join Date
    Feb 2013
    Posts
    9
    I changed the email code to the one you sent and when i clicked submit it went to a blank page that was it i recieved a email it had no information it said NameL ($name) so on for the other catergories. i also dont know where to put that success message.

  7. #7
    Join Date
    Aug 2012
    Posts
    155
    What is the name of the file where your form is? Is it contactformprocess.php?

    If it is not contactformprocess.php then you need to change the action in the form to post the form to the same page as the form is on.

    I made a slight error on the email - you need to change <br> to \n and you can't use <hr> unless you are creating an HTML email.

  8. #8
    Join Date
    Feb 2013
    Posts
    9
    my form is is on the index page i have placed it there and its target is the contactformprocess.php. how do i do this "If it is not contactformprocess.php then you need to change the action in the form to post the form to the same page as the form is on."

  9. #9
    Join Date
    Feb 2013
    Posts
    9
    i changed the <br> to \n and it still isnt showing the information Name: {$name)/nEmail etc. if i send you the index.html file and the contactformprocess.php would you be able to fix it for me and have it say the success message on the same page as a drop down will be a great help

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles