Results 1 to 5 of 5

Thread: Problem with a form not sending to email. Please help.

  1. #1
    Join Date
    Mar 2011
    Posts
    38
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Problem with a form not sending to email. Please help.

    Hi all,

    Im creating a website for the company I work for and I have made a simple contact for that asks for Name, e-mail and then a text box where they can write there message.

    Now Ive managed to style the form and it seems to work that when I hit submit it goes to a page but what it doesn't do is a) send an email to the address I have specified and b) it doesnt take the user back to the same page they were on even though I have specified this.

    The section with the form is called Drop Us A Line.

    Here is the code, there are 4 files:

    gdform.php

    PHP Code:
    <?php
        $request_method 
    $_SERVER["REQUEST_METHOD"];
        if(
    $request_method == "GET")
        {
            
    $query_vars $_GET;
        } 
        elseif (
    $request_method == "POST")
        {
            
    $query_vars $_POST;
        }

        
    reset($query_vars);
        
    $t date("U");
        
    $file $_SERVER['DOCUMENT_ROOT'] . "\ssfm\gdform_" $t;
        
    $fp fopen($file,"w");

        while (list (
    $key$val) = each ($query_vars)) 
        {
            
    fputs($fp,"<GDFORM_VARIABLE NAME=$key START>\r\n"); 
            
    fputs($fp,"$val\r\n");
            
    fputs($fp,"<GDFORM_VARIABLE NAME=$key END>\r\n");
            if (
    $key == "redirect"
            { 
                
    $landing_page $val;
            }
        }

        
    fclose($fp);
        
        if (
    $landing_page != "")
        {
            
    header("Location: http://".$_SERVER["HTTP_HOST"]."/$landing_page");
        } 
        else 
        {
            
    header("Location: http://".$_SERVER["HTTP_HOST"]."/");
        }
    ?>


    gdform.php.bak

    <?php
        $request_method 
    $_SERVER["REQUEST_METHOD"];
        if(
    $request_method == "GET")
        {
            
    $query_vars $_GET;
        } 
        elseif (
    $request_method == "POST")
        {
            
    $query_vars $_POST;
        }

        
    reset($query_vars);
        
    $t date("U");
        
    $file $_SERVER['DOCUMENT_ROOT'] . "\ssfm\gdform_" $t;
        
    $fp fopen($file,"w");

        while (list (
    $key$val) = each ($query_vars)) 
        {
            
    fputs($fp,"<GDFORM_VARIABLE NAME=$key START>\r\n"); 
            
    fputs($fp,"$val\r\n");
            
    fputs($fp,"<GDFORM_VARIABLE NAME=$key END>\r\n");
            if (
    $key == "redirect"
            { 
                
    $landing_page $val;
            }
        }

        
    fclose($fp);
        
        if (
    $landing_page != "")
        {
            
    header("Location: http://".$_SERVER["HTTP_HOST"]."/$landing_page");
        } 
        else 
        {
            
    header("Location: http://".$_SERVER["HTTP_HOST"]."/");
        }
    ?>

    sendresults.php

    PHP Code:
    <?php
    //--------------------------Set these paramaters--------------------------

    // Subject of email sent to you.
    $subject 'Contact form';

    // Your email address. This is where the form information will be sent.
    $emailadd 'richard.cc@stormdfx.com';

    // Where to redirect after form is processed.
    $url 'http://www.stormdfx.com/stormdfx';

    // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
    $req '1';

    // --------------------------Do not edit below this line--------------------------
    $text "Results from form:\n\n";
    $space ' ';
    $line '
    '
    ;
    foreach (
    $_POST as $key => $value)
    {
        if (
    $req == '1')
        {
            if (
    $value == '')
            {echo 
    "$key is empty";die;}
        }
        
    $j strlen($key);
        if (
    $j >= 20)
        {
            echo 
    "Name of form element $key cannot be longer than 20 characters";die;
        }
        
    $j 20 $j;
        for (
    $i 1$i <= $j$i++)
        {
    $space .= ' ';}
        
    $value str_replace('\n'"$line"$value);
        
    $conc "{$key}:$space{$value}$line";
        
    $text .= $conc;
        
    $space ' ';
    }
        
    mail($emailadd$subject$text'From: '.$emailadd.'');
        echo 
    '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
    ?>


    HTML

    HTML Code:
    <form action="gdform.php" method="post" name="ContactForm">
    		<fieldset>
    			<label form="name">Name:</label>
    			<input type="text" id="name" name="name" placeholder="Enter your full name" />
    			<label form="email">Email:</label>
    			<input type="text" id="email" name="email" placeholder="Enter your email address" />
    			<label form="message">Message:</label>
    			<textarea id="comments" name="comments" placeholder="What's on your mind?"></textarea>
    			<input type="submit" name="Submit" value="Submit" />
    		</fieldset>
    	</form>
    From the about PHP can you help me figure out what is going worng?

    Many Thanks,

    Rich
    Last edited by Richard Cousins; 10-10-2012 at 10:02 AM. Reason: Format: indented code

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

    Default

    I'll look at this this afternoon for you, but my first impression was that it's very ...odd. Did you find this somewhere, or are you trying to write it yourself?

  3. #3
    Join Date
    Mar 2011
    Posts
    38
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    I found as a free example to use online. Works fine on my personal portfolio site but not this one for some reason.

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

    Default

    well, the form you showed posts to gdform.php (which writes to a log file), not to sendresults.php (which sends email). All the scripts have an unusual approach to what they do, however, so there may be other issues (for example, email headers need to end with newlines [ \r\n ], and yours just end with an empty string).

    Is that first page supposed to include the sendresults page?

  5. #5
    Join Date
    Mar 2011
    Posts
    38
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Hi traq. Thanks for looking into this for. Last night I had a hunt around for another form to see if I could get it to work and modify it to change the look. I managed to find one and make it the same style and the one above, it also allows the contact form to send and e-mail to multiple e-mail addresses :-)

    I'm will update the thread so show that the problem has been resolved.

    Thanks for your help :-)

Similar Threads

  1. PHP form not sending confimation email
    By mandiemayus in forum PHP
    Replies: 0
    Last Post: 03-30-2011, 05:16 PM
  2. Sending Form in Email
    By GUIDesigner in forum HTML
    Replies: 2
    Last Post: 08-27-2010, 02:52 AM
  3. sending email problem
    By mikee.jk in forum ASP
    Replies: 1
    Last Post: 03-08-2008, 10:13 AM
  4. PHP Email Form not sending to email?
    By euphoriastudio in forum PHP
    Replies: 1
    Last Post: 02-14-2008, 08:04 PM
  5. Replies: 0
    Last Post: 04-06-2006, 05:54 PM

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
  •