SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Mail Form, Some info not being mailed

    I'm a complete noob to php and trying to fix a contact form for work. This page needs two contact forms: http://moschettalaw.com/fda-study-li...ladder-cancer/,
    I'm dealing with the bottom one currently. Any help is tremendously appreciated. I'm getting my contact emails back from tests, but several of the fields are empty. Site is in Wordpress.


    HTML:
    HTML Code:
    <h2>Actos® Bladder Cancer Contact Form</h2>
    <form id="bladder-cancer-form" action="/forms/mail2.php" enctype="multipart/form-data" method="post"><label>Name:</label>&nbsp;
    
    <input id="formname" name="formname" type="text" /> <label>
    Phone:</label>&nbsp;
    
    <input id="formphone" name="formphone" type="text" /></form> <form action="/forms/mail2.php" enctype="multipart/form-data" method="post"><label>Email:</label>&nbsp;
    
    <input id="formemail" name="formemail" type="email" /></form> <form action="/forms/mail2.php" enctype="multipart/form-data" method="post"><label>How Long Were You Taking Actos?®</label>&nbsp;
    
    <input id="formhowlong" name="formhowlong" type="text" /></form> <form action="/forms/mail2.php" enctype="multipart/form-data" method="post"><label>Where you Diagnosed with Bladder Cancer?</label>&nbsp;
    
    Yes:
    <input name="formdiagnosed" type="radio" value="Yes" />
    
    No:
    <input name="formdiagnosed" type="radio" value="No" />
    
    <label>Date of Diagnosis</label>
    
    <input id="formdate" name="formdate" type="text" /> <label></label> <label> </label>&nbsp;
    
    <label>Questions:</label>
    <textarea id="formquestions" style="width: 310px; height: 152px; margin: 2px;" name="formquestions"></textarea>
    For immediate assistance please call us at: 1-877-472-1578 Toll Free 724-225-3060 Local in PA
    
    <input class="submit" name="submit" type="submit" value="Submit" /> </form>
    PHP:
    PHP Code:
    <?

    if(isset($_POST['submit'])) {
            
    $to         "michael@piconsulting.com";
            
    $subject    "Bladder Cancer Form";
            
    $headers    "From: $formemail";
            
    }


            
    $formname        $_POST['formname'];
            
    $formphone        $_POST['formphone'];
            
    $formemail        $_POST['formemail'];
            
    $formhowlong    $_POST['formhowlong'];
            
    $formdiagnosed    $_POST['formdiagnosed'];
            
    $formdate        $_POST['formdate'];
            
    $formquestions    $_POST['formquestions'];
            
            
    $referer    $_SERVER[HTTP_REFERER];
            
    $ip         $_SERVER[REMOTE_ADDR];

            

            
    $msg       .= "Name: $formname\n";
            
    $msg       .= "Phone: $formphone\n";
            
    $msg       .= "Email: $formemail\n";
            
    $msg       .= "Response: \n";
            
    $msg       .= "Took Actos How Long: $formhowlong\n";  
            
    $msg       .= "Diagnosed?: $formdiagnosed\n"
            
    $msg       .= "Date of Diagnosis: $formdate\n"
            
    $msg       .= "Question: $formquestions\n\n"
            
            
    $msg       .= "Referer: $referer \n";
            
    $msg       .= "IP Address: $ip \n";

            
    mail($to$subject$msg$headers); 
            
            
    header ("Location:/thank-you/");
        

    ?>

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Welcome to the SP forums.

    It would help if you could tell us which fields are empty?

  3. #3
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure, thank you.

    Empty Fields in email:

    -Email Subject
    -From Email Field (Sender)
    -Name
    -Phone
    -Email
    -Took Actos How Long (formhowlong)

    A bit confused how I'm getting some data but not all when it looks like code is same for each.

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    You have the closing bracket of the if after three lines. I think you have to move it after the header (in other words at the end of the php code you posted).

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    And right now this line
    PHP Code:
    $headers    "From: $formemail"
    comes before
    PHP Code:
    $formemail        $_POST['formemail']; 
    so $formemail has no value yet.

  6. #6
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Like this? It resulted in same semi-empty email.

    PHP Code:
    <?

    if(isset($_POST['submit'])) {
            
    $to         "michael@piconsulting.com";
            
    $subject    "Bladder Cancer Form";
            
    $headers    "From: $formemail";
            



            
    $formname        $_POST['formname'];
            
    $formphone        $_POST['formphone'];
            
    $formemail        $_POST['formemail'];
            
    $formhowlong    $_POST['formhowlong'];
            
    $formdiagnosed    $_POST['formdiagnosed'];
            
    $formdate        $_POST['formdate'];
            
    $formquestions    $_POST['formquestions'];
            
            
    $referer    $_SERVER[HTTP_REFERER];
            
    $ip         $_SERVER[REMOTE_ADDR];

            

            
    $msg       .= "Name: $formname\n";
            
    $msg       .= "Phone: $formphone\n";
            
    $msg       .= "Email: $formemail\n";
            
    $msg       .= "Response: \n";
            
    $msg       .= "Took Actos How Long: $formhowlong\n";  
            
    $msg       .= "Diagnosed?: $formdiagnosed\n"
            
    $msg       .= "Date of Diagnosis: $formdate\n"
            
    $msg       .= "Question: $formquestions\n\n"
            
            
    $msg       .= "Referer: $referer \n";
            
    $msg       .= "IP Address: $ip \n";

            
    mail($to$subject$msg$headers); 
            
            
    header ("Location:/thank-you/");
        
    }
    ?>

  7. #7
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    I would change the order of things a bit. And to find the cause of the empty fields, try doing a var_dump of $_POST to see what it contains (this will cause a "headers already sent" error, but that's no problem, once the debugging is done you can delete the var_dump).
    PHP Code:
    <?

    if (isset($_POST['submit'])) {

      
    // var_dump, can be deleted when debugging is finished
      
    var_dump($_POST);

            
    $formname        $_POST['formname'];
            
    $formphone        $_POST['formphone'];
            
    $formemail        $_POST['formemail'];
            
    $formhowlong    $_POST['formhowlong'];
            
    $formdiagnosed    $_POST['formdiagnosed'];
            
    $formdate        $_POST['formdate'];
            
    $formquestions    $_POST['formquestions'];

            
    $to         "michael@piconsulting.com";
            
    $subject    "Bladder Cancer Form";
            
    $headers    "From: $formemail";
                    
            
    $referer    $_SERVER[HTTP_REFERER];
            
    $ip         $_SERVER[REMOTE_ADDR];

            
    $msg       .= "Name: $formname\n";
            
    $msg       .= "Phone: $formphone\n";
            
    $msg       .= "Email: $formemail\n";
            
    $msg       .= "Response: \n";
            
    $msg       .= "Took Actos How Long: $formhowlong\n";  
            
    $msg       .= "Diagnosed?: $formdiagnosed\n"
            
    $msg       .= "Date of Diagnosis: $formdate\n"
            
    $msg       .= "Question: $formquestions\n\n"
            
            
    $msg       .= "Referer: $referer \n";
            
    $msg       .= "IP Address: $ip \n";

            
    mail($to$subject$msg$headers); 
            
            
    header ("Location:/thank-you/");
        
    }
    ?>

  8. #8
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    guido2004,

    this is what i get:
    Code:
    array(4) { ["formdiagnosed"]=> string(3) "Yes" ["formdate"]=> string(8) "1/5/2011" ["formquestions"]=> string(14) "ahkldajshfksaj" ["submit"]=> string(6) "Submit" }
    Warning: Cannot modify header information - headers already sent by (output started at /home/moschett/public_html/forms/mail2.php:6) in /home/moschett/public_html/forms/mail2.php on line 37

  9. #9
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Ok, so the problem is the form. It's not sending all the fields you expect. Take a close look at your form again. You are closing and opening a new form for about each single form field. That means the send button will send only the fields contained in the form that contains the button as well. Get rid of all "intermediate" form opening and closing tags. Leave only the ones at the beginning and the end of the entire form.

  10. #10
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I saw that, must have made a copy/pate error, as that's not in my form code on Dreamweaver. Anywho, I tested form and I'm now getting all fields back. Thanks so much for the help! To remove var_dump, I just delete the code?

    Code:
    array(8) { ["formname"]=> string(7) "michael" ["formphone"]=> string(12) "xxx-xxx-xxxx" ["formemail"]=> string(24) "michael@piconsulting.com" ["formhowlong"]=> string(7) "3 years" ["formdiagnosed"]=> string(2) "No" ["formdate"]=> string(8) "1/5/2012" ["formquestions"]=> string(12) "testing form" ["submit"]=> string(6) "Submit" }
    Warning: Cannot modify header information - headers already sent by (output started at /home/moschett/public_html/forms/mail2.php:6) in /home/moschett/public_html/forms/mail2.php on line 37

  11. #11
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Yes, just delete the line with the var_dump.

  12. #12
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got it. Thanks so much for the help. Tremendously appreciated!

  13. #13
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    You're welcome


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
  •