Web Analytics Made Easy -
StatCounter Basic mail ( ) function question - CodingForum

Announcement

Collapse
No announcement yet.

Basic mail ( ) function question

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

  • Basic mail ( ) function question

    Hey everyone. I am brand new to PHP. I have this PHP mail script which I can't get to run properly. The only thing I get is the subject and message. What I would like is for the variables "superpowers" and "find" to be included in the message being retrieved. I tried to incorporate these through $headers variables, but they also do not show up in the message from the HTML form. Any help would be greatly appreciated:

    Code:
    <?php
    $to = '[email protected]' ;
    $email = $_POST['email'] ;
    $superpower = $_POST['superpower'] ;
    $find = $_POST['find'] ;
    $subject = $_POST['subject'] ;
    $message = $_POST['message'] ;
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= "From:".$email."\r\n";
    $headers .= "Superpower:".$superpower."\r\n";
    $headers .= "Find:".$find."\r\n";
     
    // HTML form validation
    function is_valid_email($email) {
      return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~][email protected]([0-9.]+|([^\s]+\.+[a-z]{2,6}))$#si', $email);
    }
     
    function contains_bad_str($str_to_test) {
      $bad_strings = array(
                    "content-type:"
                    ,"mime-version:"
                    ,"multipart/mixed"
            ,"Content-Transfer-Encoding:"
                    ,"bcc:"
            ,"cc:"
            ,"to:"
      );
      
      foreach($bad_strings as $bad_string) {
        if(eregi($bad_string, strtolower($str_to_test))) {
          echo "$bad_string found. Suspected injection attempt - mail not being sent.";
          exit;
        }
      }
    }
     
    function contains_newlines($str_to_test) {
       if(preg_match("/(%0A|%0D|\\n+|\\r+)/i", $str_to_test) != 0) {
         echo "newline found in $str_to_test. Suspected injection attempt - mail not being sent.";
         exit;
       }
    } 
     
    if($_SERVER['REQUEST_METHOD'] != "POST"){
       echo("Unauthorized attempt to access page.");
       exit;
    }
     
    if (!is_valid_email($email)) {
      echo 'Sorry, invalid email';
      exit;
    }
     
    contains_bad_str($email);
    contains_bad_str($subject);
    contains_bad_str(body);
     
    contains_newlines($email);
    contains_newlines($subject);
    // End HTML form validation
     
    mail( $to, $subject, $message , $headers);
    header( "Location: http://www.website.com/mailconfirm.html" );
    ?>
    Always thank those CF Users who help you solve issues...
    Connecticut Web Design

  • #2
    You probably want to append those variables to your $message variable, not your $headers variable.

    Comment


    • #3
      Thanks fumigator. I made your recommended changes based on someone elses recommendation, and it works properly now. Thanks for you reply.
      Always thank those CF Users who help you solve issues...
      Connecticut Web Design

      Comment


      • #4
        Looks like you are missing a "$" as well from here:

        contains_bad_str(body);

        But I can not see where that variable is from anyway so maybe it
        does not matter.
        If you want to attract and keep more clients, then offer great customer support.

        Support-Focus.com. automates the process and gives you a trust seal to place on your website.
        I recommend that you at least take the 30 day free trial.

        Comment

        Working...
        X