Simple contact form not working

Discussion in 'Web Design and Development' started by Fromethius, Jul 29, 2008.

  1. Fromethius macrumors member

    Joined:
    Jun 26, 2008
    Location:
    Pennsylvania
    #1
    Hello everyone. I am designing a website using html and just recently php for the contact form.

    You enter in your subject and message and hit send. Unfortunately, the message is not showing up in my inbox.

    Here is the code for the html in the contact form:

    Code:
    	  <form action="process_form.php" method="post">
    	    <table align="center" width="100">
                  <tr><td>Subject: <input type="text" name="subject"></td></tr>
    	      <tr><td>Your Message: <textarea name="message" rows="2" cols="20"></textarea></td></tr>
    	      <tr><td><input type="submit" value="Send"></td></tr>
                </table>
    	  </form>
    And for the php:

    PHP:
    <?php

    $email 
    'myemailaddress@gmail.com'// removed for post
    $subject $HTTP_POST_VARS['subject'];
    $message $HTTP_POST_VARS['message'];

    mail($email$subject$message);
    echo 
    "<h4>Thank you for sending email</h4>";

    ?>
    I enter in the subject and message, hit send, and it either sends me to the php page and shows the code, or if I fully specify the full path (localhost/day-tool/process_form.php) in the action attribute, it brings me to the web page and says, "Thank you for sending email" but the message does not show up in my inbox. Either way, I am not receiving the mail.

    What am I doing wrong?
     
  2. Me1000 macrumors 68000

    Me1000

    Joined:
    Jul 15, 2006
    #2
    Is the email address that you are sending it to hosted on the same server that the script is? Sometimes hosts prevent you from sending email to addresses that they do not host.

    also you should consider using $_POST instead of $HTTP_POST_VAR, as $HTTP_POST_VAR is depreciated... though if you are not getting an email at all, I don't think this is your problem.
     
  3. HomeBru Studios macrumors member

    HomeBru Studios

    Joined:
    Jun 4, 2008
    #3
    Do you have your machine's email services configured and running?
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    On your web host see if you can find an error log for PHP. It may have something there that can lend a clue.
     
  5. Fromethius thread starter macrumors member

    Joined:
    Jun 26, 2008
    Location:
    Pennsylvania
    #5
    I'm actually not running a web host yet. I'm testing this all using Web Sharing and up until now everything with html has been working fine.

    I also enabled php by navigating to private:etc:apache2:httpd.conf and removing the pound sign before LoadModule php5_module.

    PHP seemed to have been working fine following that.

    I'm trying to send it to my gmail account currently, so I don't know if that qualifies as being on the same server as the script (the script is on my computer).

    I also changed the http post var to post as you said so now it looks like this:

    PHP:
    <?php

    $email 
    'ethius@gmail.com';
    $subject $_POST['subject'];
    $message $_POST['message'];

    mail($email$subject$message);
    echo 
    "<h4>Thank you for sending email</h4>";

    ?>
    However, I am still receiving the same error where it just shows the php code in the browser instead of running it when not including the full filename to the php file (even though it's in the same directory).

    What do you mean by if I have my machines email services configured and running? Do I have Mail set up? Yes. It works well and is working fine for sending emails.

    I don't have a web host so I cannot really view the error log unless OS X stores one on the file system.
     
  6. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #6
    PHP, even on your own machine, can log errors. I'm not sure on the exact location. This page should help make sure error logging is turned on.

    You may also need to set your sendmail path variable in the PHP configuration. In the php.ini file search for the line with sendmail_path on it. You can probably use the default value that it mentions.

    Alternatively from using the built-in web server Apple supplies you can also try installing MAMP. MAMP installs Apache, PHP, MySQL, and other tools and gives you a little easier setup. Just an option.
     
  7. Fromethius thread starter macrumors member

    Joined:
    Jun 26, 2008
    Location:
    Pennsylvania
    #7
    I've changed both the php.ini and php.ini.default files (not sure which one to use) to look like this. The only line I changed was the sendmail_path line which was originally, ";sendmail_path = "

    PHP:
    [mail function]
    ; For 
    Win32 only.
    SMTP localhost
    smtp_port 
    25

    ; For Win32 only.
    ;
    sendmail_from me@example.com

    ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
    sendmail_path = /usr/sbin/sendmail

    Force the addition of the specified parameters to be passed as extra parameters
    to the sendmail binaryThese parameters will always replace the value of
    the 5th parameter to mail(), even in safe mode.
    ;
    mail.force_extra_parameters =
    However, it still does not send me a mail message.
     

Share This Page