Problem with php code for a mail contact form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • snapscan
    New Member
    • Nov 2008
    • 3

    Problem with php code for a mail contact form

    Hello,

    I am new to PHP code and I have copied the following code from the internet to create a contact page on my web site.


    Code:
    <?
    $subject="from ".$_GET['your_name'];
    $headers= "From: ".$_GET['your_email']."\n";
     $headers='Content-type: text/html; charset=iso-8859-1';
    mail("<emailremoved>", $subject,"
    <html>
    <head>
     <title>Contact letter</title>
    </head>
    <body>
    
    <br>
      ".$_GET['message']."
    </body>
    </html>" , $headers);
    echo ("Your message was successfully sent";
    ?>
    <script>
    	resizeTo(300, 300)
    	//window.close()
    </script>
    
    
    
    
    
    
    
    However when the script is run I get the following error
    
    ".$_GET['message']." " , $headers); echo ("Your message was successfully sent!"); ?>
    Can any one help please?
    Last edited by Markus; Nov 14 '08, 09:56 PM. Reason: added # tags & removed email
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Sure, we'd love to help, but in order for that to happen you've got to do a few things:
    • Use [code] tags when supplying code
    • Provide us with *all* relevant information - the info you gave is next to nothing, and certainly not enough to help you with
    • Tell us the errors
    • Tell us what didn't happen
    • Tell us what you wanted to happen
    • Tell us what *did* happen


    Also, do not post email addresses.

    Please read the Posting Guidelines to avoid these errors and others.

    Moderator.
    Last edited by Markus; Nov 14 '08, 10:00 PM. Reason: added posting guidelines

    Comment

    • snapscan
      New Member
      • Nov 2008
      • 3

      #3
      Sorry


      The error message is at the end of the code, On my email form I input a name, email address and text. Then I press the submit button and get a window opening 300X 300 with the text listed at the end of the code. No email is sent. I am testing the code on a laptop using XAMPP. The variable name and email address are listed at the top of the window so they look to be set OK . The prblem looks to be with the email comand .......?


      Thanks

      Comment

      • maheswaran
        New Member
        • Mar 2007
        • 190

        #4
        see

        echo ("Your message was successfully sent";

        is not closed...

        Comment

        • snapscan
          New Member
          • Nov 2008
          • 3

          #5
          Thanks for the response,

          I have changed the line echo ("your message was successfully sent!");
          However I get the same problem but your point about closing () would the line
          mail("XXX@XXXXX ", $subject," need to be changed / closed

          Thanks

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Is this a .php file ?
            Is your server running PHP?

            If you view of the source code of the page, what is the output?

            Comment

            • nathj
              Recognized Expert Contributor
              • May 2007
              • 937

              #7
              Originally posted by snapscan
              Thanks for the response,

              I have changed the line echo ("your message was successfully sent!");
              However I get the same problem but your point about closing () would the line
              mail("XXX@XXXXX ", $subject," need to be changed / closed

              Thanks
              Looking through the code I can see that the line you mention is actually closed further down with the code:
              Code:
              </HTML>",$headers);
              (something similar, I can't see it while I type this). Basically this code is trying to set up an HTML email message and send it using the normal mail functions in PHP.

              I would either, ditch the HTML part and have a simple text only email, or read up on headers to make sure they are correct. (Google PHP mail ) the top result should help)

              Either way I would build up the message in a separate variable first and then include that variable as the message parameter.

              Cheers
              nathj

              Comment

              • anujitkarmakar
                New Member
                • Nov 2008
                • 2

                #8
                change

                echo ("Your message was successfully sent";

                to

                echo ("Your message was successfully sent");

                this may solve your problem. If it does not solve your problem let me know again.

                Comment

                • maheswaran
                  New Member
                  • Mar 2007
                  • 190

                  #9
                  Please check ur server which it allow short tag function <? and ?>

                  else u need to put <?php ?>

                  Try with this

                  Start php lie

                  <?php
                  <!-- ur codes -->
                  ?>

                  Comment

                  • nathj
                    Recognized Expert Contributor
                    • May 2007
                    • 937

                    #10
                    Originally posted by maheswaran
                    Please check ur server which it allow short tag function <? and ?>

                    else u need to put <?php ?>

                    Try with this

                    Start php lie

                    <?php
                    <!-- ur codes -->
                    ?>
                    The simple solution on this one is to always use the full tag <?php ... ?> and not the short tags, no need to check the server, just do it.
                    nathj

                    Comment

                    • r035198x
                      MVP
                      • Sep 2006
                      • 13225

                      #11
                      If you are new to PHP then you should read the PHP tutorial first. There is no point in just downloading some code and trying to automagically turn it into working code without understanding the language.

                      Comment

                      • nathj
                        Recognized Expert Contributor
                        • May 2007
                        • 937

                        #12
                        Originally posted by r035198x
                        If you are new to PHP then you should read the PHP tutorial first. There is no point in just downloading some code and trying to automagically turn it into working code without understanding the language.
                        That's the best advice you've been given so far.

                        Here's the tutorial that got me started: W3Schools PHP tutorial the other site that will prove invaluable is this one.

                        Cheers
                        nathj

                        Comment

                        Working...