Web Analytics Made Easy -
StatCounter Function need help ;) .. - CodingForum

Announcement

Collapse
No announcement yet.

Function need help ;) ..

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Resolved Function need help ;) ..

    hey im doing this site with a contact me form and i coded a function to test everything but when im running it just sends a mail with nothing whithout cheking it ;S


    here is the my function file
    PHP Code:
    <?php

    $msg
    ;
    $post $_POST['post'];
    function 
    mailer($to,$from,$message,$hidden,$subject){
    global 
    $msg;
    global 
    $post;
        if(!empty(
    $post)){

            if(!empty(
    $hidden)) {
            
    $sendit 0;

            
    $msg "<p style=\"background-color:red;text-align:center;\">BIIIGGG FAIL! GET OFF ****ING SPAM MACHINE</p>";
    }
            else{
            if(empty(
    $to) || empty($from) || empty($message)){

            
    $msg ="<p style=\"background-color:red;text-align:center;\">Please fill out all fields</p>";
            
    $sendit 0;
    }
        else{
        
    $sendit 1;
    }




    }

    }

        if(
    $send=1){
        
    $headers "From: \"".$from."\" <".$from.">\n";
        
    $headers .= "To: \"".$to."\" <".$to.">\n";
        
    $headers .= "MIME-Version: 1.0\n";
        
    $headers .= "Content-Type: text/HTML; charset=ISO-8859-1\n"
            if(
    mail($to$subject$message$headers)){

            
    $msg ="<p style=\"background-color:green;text-align:center;\">Thanks for your message ;)</p>";

    }
        else{

        
    $msg ="<p style=\"background-color:red;text-align:center;\">Something went wrong might me the mail serverplease try again later</p>";

    }
        




    }



    }



    ?>
    and here are the html with the form
    PHP Code:
     <?php require("class_lib.php"); ?>
    <?php



    mailer
    ("[email protected]",$_POST['cemail'],$_POST['cmessage'],$_POST['chidden'],"Contact me form");


    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
     
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
      <head>  
        <title>Hmail | BETA - Contact</title>
        <meta http-equiv="content-type" content="text/html;charset=utf-8" />
        <meta http-equiv="Content-Style-Type" content="text/css" />

        <link rel="stylesheet" type="text/css" href="style.css" />  
      </head>
      <body>
    <!-- header start -->
    <div id="header">

    <a href="http://hmail.servegame.org/home">
    <img src="images/logo.jpg" style="width:280px; height:122px;" alt="logo" /></a>
    </div>
    <!-- header end -->
    <!-- wrapper start -->
    <div id="wrapper">
        <!-- menu start -->
        <div id="menu">
        <h2>Navigation</h2>
        <ul>
        <li><a href="index.php">Home</a></li>
        <li><a href="about.php">About me</a></li>
        <li><a href="contact.php">Contact me</a></li>
        
        </ul>
        <h2>Login</h2>
        <form method="post" action="#">
        <label>Username:</label>
        <input type="text" name="username" class="txtBox" />
        <label>Password:</label>
        <input type="password" name="password" class="txtBox" />

        <a href="register.php">Not a member yet??</a>
        <input type="submit" name="go" value="Go" class="go" />

        </form>
        </div>
        <!-- menu end -->


        <!-- content start -->
        <div id="content">
        <h2>Contact me</h2>
        <?php echo $msg?>
        <p>Hey just fill it out and send it ;)</p>
        
        <form method="post" target="<?php echo "$_phpself()"?>" id="contact">
        <input type="text" name="chidden" class="hidden" >
        <span>Name:</span>
        <input type="text" name="cname" class="ctxtBox">
        <span>Email:</span>
        <input type="text" name="cemail" class="ctxtBox">
        <span>Message</span>
        <textarea class="ctxtarea" name="cmessage"> </textarea>
        <input type="submit" value="Send">
        <input type="text" name="post" value="posted" class="hidden" >
        </form>
        
        



        </div>
        <!-- content end -->

        <!-- footer start -->
        <div id="footer">
     <p>&copy; 2009 <a href="http://hmail.servegame.org/home">Hmail.servegame.org</a> | All rights reserved.</p>
        </div>

        <!-- footer end -->
    </div>
    <!-- wrapper end -->

    </body>
    </html>
    hope you can help me thanks ...
    Last edited by diload; Apr 13, 2009, 12:58 PM.

  • #2
    First check if the form was posted before sending the email:
    PHP Code:
    <?php require("class_lib.php"); ?>
    <?php


    if ( ! empty( $_POST ) )
    {
        
    mailer("[email protected]",$_POST['cemail'],$_POST['cmessage'],$_POST['chidden'],"Contact me form");
    }
    ZCE

    Comment


    • #3
      ye thanks that helped a bit but now im getting the errori maded here
      PHP Code:
          if($sendit="1"){
              
      $headers "From: \"".$from."\" <".$from.">\n";
              
      $headers .= "To: \"".$to."\" <".$to.">\n";
              
      $headers .= "MIME-Version: 1.0\n";
              
      $headers .= "Content-Type: text/HTML; charset=ISO-8859-1\n"
              if(
      mail($to$subject$message$headers)){

                  
      $msg ="<p style=\"background-color:green;text-align:center;\">Thanks for your message ;)</p>";

      }
                  else{

                  
      $msg ="<p style=\"background-color:red;text-align:center;\">Something went wrong might me the mail serverplease try again later</p>";

      }
          





      the red error shows up all the time even before i submitted the form:S

      Comment


      • #4
        Nevermind i found it out i didnt got the last piece in my function :S .... Slap me ...

        Comment


        • #5
          Originally posted by diload View Post
          ye thanks that helped a bit but now im getting the errori maded here
          PHP Code:
              if($sendit="1"){
                  
          $headers "From: \"".$from."\" <".$from.">\n";
                  
          $headers .= "To: \"".$to."\" <".$to.">\n";
                  
          $headers .= "MIME-Version: 1.0\n";
                  
          $headers .= "Content-Type: text/HTML; charset=ISO-8859-1\n"
                  if(
          mail($to$subject$message$headers)){

                      
          $msg ="<p style=\"background-color:green;text-align:center;\">Thanks for your message ;)</p>";

          }
                      else{

                      
          $msg ="<p style=\"background-color:red;text-align:center;\">Something went wrong might me the mail serverplease try again later</p>";

          }
              





          the red error shows up all the time even before i submitted the form:S
          this is wrong, it's not a test:
          PHP Code:
              if($sendit="1"){ 
          best regards

          Comment


          • #6
            thanks but now i got 1 more problem (hopefully the last ^^)

            when im submitting the form it dosnt check for empty fields ;S it jsut sends the mail ;S

            function php

            PHP Code:
            <?php

            $msg
            ;
            $post $_POST['post'];
            function 
            mailer($to,$from,$message,$hidden,$subject,$name){//function mailer start
            global $msg;
            global 
            $post;



                    if(!empty(
            $hidden)) {//if start
                    
            $sendit =0;

                    
            $msg "<p style=\"background-color:red;text-align:center;\">BIIIGGG FAIL! GET OFF ****ING SPAM MACHINE</p>";
            }
            //if end
                    
            elseif(empty($to) || empty($from) || empty($message)){//elseif start

                    
            $msg ="<p style=\"background-color:red;text-align:center;\">Please fill out all fields</p>";
                    
            $sendit =0;
            }
            //elseif end
                
            else{//else start
                
            $sendit =1;
            }
            //else end








                

                
            if($sendit=1){//if start
                    
            $headers "From: [email protected]\n";
                    
            $headers .= "To: \"".$to."\" <".$to.">\n";
                    
            $headers .= "MIME-Version: 1.0\n";
                    
            $headers .= "Content-Type: text/HTML; charset=ISO-8859-1\n"
                    
            $message "this is send from your home page by: \"".$name."\" \""$from."\"<br >" $message;
                    if(
            mail($to$subject$message$headers)){//if start

                        
            $msg ="<p style=\"background-color:green;text-align:center;\">Thanks for your message ;)</p>";

            }
            //1. if end
                        
            else{//else start

                        
            $msg ="<p style=\"background-color:red;text-align:center;\">Something went wrong might me the mail serverplease try again later</p>";

            }
            //else end
                




            }//2. if ends



            }//function end




            ?>

            Comment


            • #7
              Originally posted by diload View Post
              thanks but now i got 1 more problem (hopefully the last ^^)
              what did you change and how?

              to be test must be:
              PHP Code:
              if($sendit == "1"){ 
              best regards

              Comment


              • #8
                Arrrgh dammit Thank you so much im loosing my memory i can remember how i learned that 1 in the start but it is the first script im writing for at least an ½year ....


                sorry if my english is bad :S ...


                And again thank you for your time for that stupid mistake ...

                Comment

                Working...
                X