Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    New Coder
    Join Date
    Jun 2010
    Location
    New Hampshire Seacoast
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Please help with PHP based contact form.

    Hey folks,

    I have been working toward filling gaps in my coding knowledge, and I hope to tackle PHP soon, but in the meantime I am stumbling through the creation of a simple PHP based contact form in order to put the finishing touches on a website.

    I've taken the code from a super basic (and license free) tutorial and tailored it to my needs. Everything appears to work, except that I do not receive the test email, sent from the form.

    The tutorial had me create two .php files. One for the page on the site containing the form, and another for it to communicate with in order to send the email. The first file is actually XHTML (with a touch of JavaScript, which I'm new to), but the tutorial told me to use the .php extension, so I have.

    Here is the current code for both files (sans the XHTML):

    Contact.php

    Code:
    <form action="ContactSend.php" method="post" enctype="text/plain" name="EmailForm" id="EmailForm">
    <input type="text" name="name" id="name" value="Name" width="150px" style="color:#999999;" onFocus="this.value='';this.onfocus=null;this.style.cssText='';" /> 
    <input type="text" name="email" id="email" value="Email" width="150px" style="color:#999999;" onFocus="this.value='';this.onfocus=null;this.style.cssText='';" /><br /><br />
    <input type="text" name="subject" id="subject" value="Subject" width="310px" style="color:#999999;" onFocus="this.value='';this.onfocus=null;this.style.cssText='';" /><br /><br />
    <textarea name="message" id="message" rows="7" cols="40" style="color:#999999;" onFocus="this.value='';this.onfocus=null;this.style.cssText='';">Type your message here...</textarea>
    <br />
    <input type="submit" name="send" value="Send">
    </form>
    and ContactSend.php

    Code:
    <?php
    // Contact subject
    $subject ="$subject";
    // Details
    $message="$message";
    
    // Mail of sender
    $from="$email";
    // From
    $header="from: $name <$from>";
    
    // Enter your email address
    $to ='my@private.email';
    
    $send=mail($to,$subject,$message,$header);
    
    // Check, if message sent to your email
    // display message "We've recived your information"
    if($send){
    echo "<b>Thank you</b>.<br />We will get back to you very soon.";
    }
    else {
    echo "<b>ERROR</b>: Please be sure that you complete all fields and try again.";
    }
    ?>
    Again, the remaining issue is simply that the test email doesn't arrive in my inbox. I successfully reach the page with the quote: "Thank you. We will get back to you very soon."

    Seems like this should be SUCH a simple task. Any help will be so appreciated. : )
    Gracious thanks!
    -Tye
    Last edited by TyeNewton; 07-02-2010 at 07:07 AM. Reason: I realized that I mislabeled my own code.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Who is your webhost and do you know if they allow the use of php's mail() function? Some hosts don't allow it in fear of spam.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Jun 2010
    Location
    New Hampshire Seacoast
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The host is GoDaddy. Considering their high profile, I'd expect they'd cover all the bases, but I guess I don't know... I know there was mention of php support during sign up, but you're just talking about the mail() function, I see.

    Do you know where I should look for this information on GoDaddy's site? This is only the third time I've ever purchased hosting, and everything still seems very cluttered and convoluted to me.

    Thanks! : )

  • #4
    New Coder
    Join Date
    Oct 2009
    Posts
    26
    Thanks
    2
    Thanked 1 Time in 1 Post
    Create an example PHP file and adding the following inside:

    PHP Code:
    <?php
    if ( function_exists'mail' ) )
    {
        echo 
    'mail() is available';
    }
    else
    {
        echo 
    'mail() has been disabled';

    ?>
    This will tell you if PHP mail() function is either enabled or disabled

  • #5
    New Coder
    Join Date
    Jun 2010
    Location
    New Hampshire Seacoast
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I was writing this reply as I discovered Benny's, so here it is first...

    --

    Oh, look!
    This super brief article appears to be confirming support for the php mail() function:
    http://community.godaddy.com/help/article/951

    Looks pretty generalized so it must cover all GoDaddy accounts, right??

    --

    I suppose I should still try your idea, though, Benny.
    Are you suggesting I swap your code with my ContactSend.php file, then use the form to test it?? (Sorry about my lack of php knowledge.)

  • #6
    Regular Coder
    Join Date
    Aug 2008
    Posts
    133
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by TyeNewton View Post
    I suppose I should still try your idea, though, Benny.
    Are you suggesting I swap your code with my ContactSend.php file, then use the form to test it?? (Sorry about my lack of php knowledge.)

    No he isn't. Just create a php file with that code (i.e. just go to notepad and rename to .php) and upload to you web server. Then run the script by going to yourwebserver/nameofphpfile.php. The code will output a message in your browser saying whether you are able to use the mail function.

  • #7
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    No just create one file and put nothing else but Benny's code in it, upload it to your site, and navigate to the file. What does it tell you?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #8
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    At one time, GoDaddy only allowed PHP mail() to be sent to the email
    that was assigned to the account (in your GoDaddy settings).

    Not sure if they changed that or not, but you might want to check their documentation.

  • #9
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Also turn on error reporting to see if any errors are being returned. Change this
    PHP Code:
    <?php
    // Contact subject
    $subject ="$subject";
    to this
    PHP Code:
    <?php
    ini_set
    ('display_errors','On');
    error_reporting(E_ALL);
    // Contact subject
    $subject ="$subject";
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #10
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Does GoDaddy force the use of their gdform.php form mailer? Or is that just a dummies version of form mailing? I know there have been several questions on that here. A forum search might turn up something.
    Are you a Help Vampire?

  • #11
    New Coder
    Join Date
    Jun 2010
    Location
    New Hampshire Seacoast
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you, everyone, so much for the assistance!

    Good news:
    I tried Benny's test for mail() function support and it turned up positive.

    Interesting news:
    I also tried Aerospace's error-checking suggestion and received the following report...

    "Notice: Undefined variable: subject in /home/content/m/t/n/mtnfinishing/html/ContactSend.php on line 5

    Notice: Undefined variable: message in /home/content/m/t/n/mtnfinishing/html/ContactSend.php on line 7

    Notice: Undefined variable: email in /home/content/m/t/n/mtnfinishing/html/ContactSend.php on line 10

    Notice: Undefined variable: name in /home/content/m/t/n/mtnfinishing/html/ContactSend.php on line 12"

    Looking back at my code, the lines it refers to are $subject ="$subject";, $message="$message";, $from="$email";, and $header="from: $name <$from>";. Basically every single variable received from the form.
    Does this mean that it is in fact NOT receiving information from the form? If so, I must be reaching the "Thank you." message in error, correct?
    On the other hand, if it IS receiving information from the form, then I can understand why it wouldn't like my "subject" and "message" variables, as those appear to refer to themselves, but I'm at a total loss as to why it doesn't like my "from" and "header" variables. : /

    This is actually a website for my own father's business, so in the meantime, I am going to attempt to test out miseim's hypothesis by changing the "to" address to my father's email (the one associated with the GoDaddy account).

    Thanks so much, to everyone, again!

  • #12
    New Coder
    Join Date
    Jun 2010
    Location
    New Hampshire Seacoast
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I forgot to also add that I don't fully grasp what tomws is asking about. I wouldn't be surprised if what I'm using is a "dummies" version, however. ; )

    Okay, so nothing was received by my father's email, either. However, I'm wondering now if mlseim (oops! I misspelled your username before) meant that the address has to be associated with the domain? My father still prefers to use his ISP email address, so we didn't bother purchasing email support with the domain.
    I'll poke around at GoDaddy's documentation for an answer, in any case.

    (Is it weird that I'm referring to everyone in the third person? I'm do more search than posting on forums, so I apologize if my posting habits appear rude. Also, should I be quoting people more?)

  • #13
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Re: undefined variable. You're not "catching" the values from the form. The assignments you're using worked in PHP4, but not in PHP5 (unless the server operator has opened up a little security hole). Use this instead:
    PHP Code:
    $myVar $_POST['myVar'];
    // or
    $myVar $_GET['myVar']; 
    Are you a Help Vampire?

  • #14
    New Coder
    Join Date
    Jun 2010
    Location
    New Hampshire Seacoast
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks tomws.

    So I've turned this:

    Code:
    <?php
    ini_set('display_errors','On');
    error_reporting(E_ALL);
    // Contact subject
    $subject ="$subject";
    // Details
    $message="$message";
    
    // Mail of sender
    $from="$email";
    // From
    $header="from: $name <$from>";
    
    // Enter your email address
    $to ='my@private.add';
    
    $send=mail($to,$subject,$message,$header);
    
    // Check, if message sent to your email
    // display message "We've recived your information"
    if($send){
    echo "<b>Thank you</b>.<br />We will get back to you very soon.";
    }
    else {
    echo "<b>ERROR</b>: Please be sure that you complete all fields and try again.";
    }
    ?>
    Into this:

    Code:
    <?php
    ini_set('display_errors','On');
    error_reporting(E_ALL);
    // Contact subject
    $subject = $_Get[ '$subject' ];
    // Details
    $message = $_Get[ '$message' ];
    
    // Mail of sender
    $from = $_Get[ '$email' ];
    // From
    $header = $_Get[ 'from: $name <$from>' ];
    
    // Enter your email address
    $to = $_Post[ 'my@private.add' ];
    
    $send=mail($to,$subject,$message,$header);
    
    // Check, if message sent to your email
    // display message "We've recived your information"
    if($send){
    echo "<b>Thank you</b>.<br />We will get back to you very soon.";
    }
    else {
    echo "<b>ERROR</b>: Please be sure that you complete all fields and try again.";
    }
    ?>
    I'm not sure if I needed the $_POST for the "to" address, or if this is even correct at all.(?) Seems like there must be something more I need to do to the $send and $header variables.

  • #15
    New Coder
    Join Date
    Jun 2010
    Location
    New Hampshire Seacoast
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wuh-oh,
    This time all of the same variables plus line 15 (the "to" address) turned up undefined.
    I guess I didn't translate that properly, haha.

    I apologize again for tackling this with so little prior php knowledge. Again, I intend to properly learn javascript and php after I finish with the first installment of this and another website.


  •  
    Page 1 of 2 12 LastLast

    Tags for this Thread

    Posting Permissions

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