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.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post

    Blind copy question

    Hello

    How would I add a blind copy to the following code, please, so that a copy goes to the Webmaster and a BCC to that Webmaster's personal email account?

    Many thanks for any help.

    Steve

    Code:
    /* Email address where the messages should be delivered */
    $to = 'info@oursite.com';
    $from = 'info@oursite.com';
    
    $subject_prefix = 'Thank you for your enquiry';
    
    $header_file = 'form-header.php';
    $footer_file = 'form-footer.php';
    $form_width = '70%';
    $form_background = '#F7F8F7';
    $form_border_color = '#CCCCCC';
    $form_border_width = '1px';
    $form_border_style = 'solid';
    $cell_padding = '5px';
    $left_col_width = '25%';
    $font_size = '12px';
    
    $field_error_color = '#FF0000';
    
    $thank_you_message = <<<EOD
    <p>Thank you for your message. WE will contact you within 24 hours.</p><br /><br /><br /><br /><br /><br /><br /><br />
    
    EOD;
    
    = 'http://www.ourwebsite.com/thank_you.html'; */
    
    $thank_you_url = '';
    
    
    $name = array('Name','name',NULL,NULL);
    $email = array('Email','email',NULL,NULL,NULL);
    $subject = array('Subject','subject',NULL,NULL);
    $message = array('Message','message',NULL,NULL);
    $security = array('Security question','security',NULL,NULL,NULL);
    
    $error_message = '';
    
    if (!isset($_POST['submit'])) {
    
      showForm();
    
    } else { //form submitted
    
      $error = 0;
      
      if(!empty($_POST['check'])) die("Invalid form access");
      
      if(!empty($_POST['name'])) {
      	$name[2] = clean_var($_POST['name']);
      	if (function_exists('htmlspecialchars')) $name[2] = htmlspecialchars($name[2], ENT_QUOTES);
      }
      else {
        $error = 1;
        $name[3] = 'color:#FF0000;';
      }
      
      if(!empty($_POST['email'])) {
      	$email[2] = clean_var($_POST['email']);
      	if (!validEmail($email[2])) {
      	  $error = 1;
      	  $email[3] = 'color:#FF0000;';
      	  $email[4] = '<strong><span style="color:#FF0000;">Invalid email</span></strong>';
    	  }
      }
      else {
        $error = 1;
        $email[3] = 'color:#FF0000;';
      }
      
      if(!empty($_POST['subject'])) {
      	$subject[2] = clean_var($_POST['subject']);
      	if (function_exists('htmlspecialchars')) $subject[2] = htmlspecialchars($subject[2], ENT_QUOTES);  	
      }
      else {
      	$error = 1;
        $subject[3] = 'color:#FF0000;';
      }  
    
      if(!empty($_POST['message'])) {
      	$message[2] = clean_var($_POST['message']);
      	if (function_exists('htmlspecialchars')) $message[2] = htmlspecialchars($message[2], ENT_QUOTES);
      }
      else {
        $error = 1;
        $message[3] = 'color:#FF0000;';
      }    
    
      if(empty($_POST['security'])) {
        $error = 1;
        $security[3] = 'color:#FF0000;';
      } else {
      	
        if($question_answers[$_POST['question']] != strtolower(clean_var($_POST['security']))) {
          $error = 1;
          $security[3] = 'color:#FF0000;';   
          $security[4] = '<strong><span style="color:#FF0000;">Wrong answer</span></strong>';
        }
      }
    
      if ($error == 1) {
        $error_message = '<span style="font-weight:bold;font-size:90%;">Please correct/enter field(s) in red.</span>';
    
        showForm();
    
      } else {
      	
      	if (function_exists('htmlspecialchars_decode')) $name[2] = htmlspecialchars_decode($name[2], ENT_QUOTES);
      	if (function_exists('htmlspecialchars_decode')) $subject[2] = htmlspecialchars_decode($subject[2], ENT_QUOTES);
      	if (function_exists('htmlspecialchars_decode')) $message[2] = htmlspecialchars_decode($message[2], ENT_QUOTES);  	
      	
        $message = "$name[0]: $name[2]\r\n$email[0]: $email[2]\r\n\r\n$message[0]:\r\n$message[2]\r\n";
        
        if (!$from) $from_value = $email[2];
        else $from_value = $from;
        
        $headers = "From: $from_value" . "\r\n" . "Reply-To: $email[2]";
        
        mail($to,"$subject_prefix - $subject[2]", $message, $headers);
        
        if (!$thank_you_url) {
        
          include $header_file;
          echo $GLOBALS['thank_you_message'];
          echo "\n";
          include $footer_file;
    	  }
    	  else {
    	  	header("Location: $thank_you_url");
    	  }
           	
      }
    
    } //else submitted
    
    
    
    function showForm()
    
    {
    global $name, $email, $subject, $message, $security, $question_answers, $header_file, $footer_file, $form_width, $form_background, $form_border_color, $form_border_width, $form_border_style, $cell_padding, $left_col_width, $font_size; 
    include $header_file;
    $question = array_rand($question_answers);
    echo $GLOBALS['error_message'];  
    echo <<<EOD
    
    <form method="post" class="cForm">
    <table style="width:{$form_width}; background-color:{$form_background}; border:{$form_border_width} {$form_border_style} {$form_border_color}; padding:10px; font-size:{$font_size};" class="contactForm">
    <tr>
    <td style="width:{$left_col_width}; text-align:left; vertical-align:top; padding:{$cell_padding}; font-weight:bold; {$name[3]}">{$name[0]}</td>
    <td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><input type="text" name="{$name[1]}" value="{$name[2]}" /></td>
    </tr>
    <tr>
    <td style="width:{$left_col_width}; text-align:left; vertical-align:top; padding:{$cell_padding}; font-weight:bold; {$email[3]}">{$email[0]}</td>
    <td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><input type="text" name="{$email[1]}" value="{$email[2]}" /> {$email[4]}</td>
    </tr>
    <tr>
    <td style="width:{$left_col_width}; text-align:left; vertical-align:top; padding:{$cell_padding}; font-weight:bold; {$subject[3]}">{$subject[0]}</td>
    <td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><input type="text" name="{$subject[1]}" value="{$subject[2]}" size="40" /></td>
    </tr>
    <tr>
    <td style="width:{$left_col_width}; text-align:left; vertical-align:top; padding:{$cell_padding}; font-weight:bold; {$message[3]}">{$message[0]}</td>
    <td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><textarea name="{$message[1]}" cols="40" rows="6">{$message[2]}</textarea></td>
    </tr>
    <td style="width:{$left_col_width}; text-align:left; vertical-align:top; padding:{$cell_padding}; font-weight:bold; {$security[3]}">{$question}?</td>
    <td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><input type="text" name="{$security[1]}" value="" size="10" /> {$security[4]}
    <br /><br />We are sorry but please answer the above question to prove you are a real visitor and not a spam bot.</td>
    </tr>
    <tr>
    <td colspan="2" style="text-align:left; vertical-align:middle; padding:{$cell_padding}; font-size:90%; font-weight:bold;">All fields are required.</td>
    </tr>
    <tr>
    <td colspan="2" style="text-align:left; vertical-align:middle; padding:{$cell_padding};"><input type="submit" name="submit" value="Submit" style="border:1px solid #999;background:#E4E4E4;margin-top:5px;" /></td>
    </tr>
    </table>
    <input type="hidden" name="question" value="{$question}">
    <input type="hidden" name="check" value="">
    </form>
    <div style="width:{$form_width};text-align:right;font-size:80%;">
    <a href="http://www.easyphpcontactform.com/" title="PHP Contact Form">PHP Contact Form</a>
    </div> 
    EOD;
    
    include $footer_file;
    }
    
    function clean_var($variable) {
        $variable = strip_tags(stripslashes(trim(rtrim($variable))));
      return $variable;
    }
    
    /**
    Email validation function. Thanks to http://www.linuxjournal.com/article/9585
    */
    function validEmail($email)
    {
       $isValid = true;
       $atIndex = strrpos($email, "@");
       if (is_bool($atIndex) && !$atIndex)
       {
          $isValid = false;
       }
       else
       {
          $domain = substr($email, $atIndex+1);
          $local = substr($email, 0, $atIndex);
          $localLen = strlen($local);
          $domainLen = strlen($domain);
          if ($localLen < 1 || $localLen > 64)
          {
             // local part length exceeded
             $isValid = false;
          }
          else if ($domainLen < 1 || $domainLen > 255)
          {
             // domain part length exceeded
             $isValid = false;
          }
          else if ($local[0] == '.' || $local[$localLen-1] == '.')
          {
             // local part starts or ends with '.'
             $isValid = false;
          }
          else if (preg_match('/\\.\\./', $local))
          {
             // local part has two consecutive dots
             $isValid = false;
          }
          else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
          {
             // character not valid in domain part
             $isValid = false;
          }
          else if (preg_match('/\\.\\./', $domain))
          {
             // domain part has two consecutive dots
             $isValid = false;
          }
          else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local)))
          {
             // character not valid in local part unless 
             // local part is quoted
             if (!preg_match('/^"(\\\\"|[^"])+"$/',
                 str_replace("\\\\","",$local)))
             {
                $isValid = false;
             }
          }
          if ($isValid && function_exists('checkdnsrr'))
          {
          	if (!(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) {
             // domain not found in DNS
             $isValid = false;
           }
          }
       }
       return $isValid;
    }
    
    ?>

  • #2
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    You should be able to add a Bcc line to the headers. Check here for guidance:
    http://php.net/manual/en/function.mail.php
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #3
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    Hello Rowsdower

    So the script would be like this:

    Code:
    $to = 'info@oursite.com';
    $from = 'info@oursite.com';
    $headers .= 'Bcc: personal_email@example.com' . "\r\n";
    $subject_prefix = 'Thank you for your enquiry';
    But that 'dot' before the equals sign (=) that I have copied and pasted from the manual, is that right?

    Cheers

    Steve

  • #4
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Change the following line
    PHP Code:
    $headers "From: $from_value" "\r\n" "Reply-To: $email[2]"
    to
    PHP Code:
    $headers "From: $from_value\r\nReply-To: $email[2]\r\nBCC: blindcopyaddress@yoursite.com"
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #5
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    Hello Jay6390

    Is that instead of

    Code:
    $headers .= 'Bcc: personal_email@example.com' . "\r\n";
    ?

    Thanks

  • #6
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    In your original code you posted you have
    $headers = "From: $from_value" . "\r\n" . "Reply-To: $email[2]";
    so just replace that line with the one I gave
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #7
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    I have this form here:

    http://proofreading4students.com/con...ntact-form.php
    and it does not appear to be working at all - nothing to the Webmaster or the blind recipient.

    I have incorporated the change - thanks, Jay.

    Code:
    /* Email address where the messages should be delivered */
    $to = 'webmaster@ourSite.com';
    
    /* From email address, in case your server prohibits sending emails from addresses other than those of your 
    own domain (e.g. email@yourdomain.com). If this is used then all email messages from your contact form will appear 
    from this address instead of actual sender. */
    $from = 'info@ourSite.com';
    
    /* This will be appended to the subject of contact form message */
    $subject_prefix = 'Thank you for your enquiry';
    
    /* Security question and answer array */
    $question_answers = array (
    'Moon is red or white' => 'white',
    'Sun is blue or yellow' => 'yellow',
    'Fire is hot or cold' => 'hot',
    'Icecream is hot or cold' => 'cold'
    );
    
    /* Form header file */
    $header_file = 'form-header.php';
    
    /* Form footer file */
    $footer_file = 'form-footer.php';
    
    /* Form width in px or % value */
    $form_width = '70%';
    
    /* Form background color */
    $form_background = '#F7F8F7';
    
    /* Form border color */
    $form_border_color = '#CCCCCC';
    
    /* Form border width */
    $form_border_width = '1px';
    
    /* Form border style. Examples - dotted, dashed, solid, double */
    $form_border_style = 'solid';
    
    /* Form cell padding */
    $cell_padding = '5px';
    
    /* Form left column width */
    $left_col_width = '25%';
    
    /* Form font size */
    $font_size = '12px';
    
    /* Empty/Invalid fields will be highlighted in this color */
    $field_error_color = '#FF0000';
    
    /* Thank you message to be displayed after the form is submitted. Can include HTML tags. Write your message 
    between <!-- Start message --> and <!-- End message --> */
    $thank_you_message = <<<EOD
    <!-- Start message -->
    <p>We have received your message. If required, we'll get back to you as soon as possible.</p><br /><br /><br /><br /><br /><br /><br /><br />
    <!-- End message -->
    EOD;
    
    /* URL to be redirected to after the form is submitted. If this is specified, then the above message will 
    not be shown and user will be redirected to this page after the form is submitted */
    /* Example: $thank_you_url = 'http://www.yourwebsite.com/thank_you.html'; */
    
    $thank_you_url = '';
    
    /*******************************************************************************
     *	Do not change anything below, unless of course you know very well 
     *	what you are doing :)
    *******************************************************************************/
    
    $name = array('Name','name',NULL,NULL);
    $email = array('Email','email',NULL,NULL,NULL);
    $subject = array('Subject','subject',NULL,NULL);
    $message = array('Message','message',NULL,NULL);
    $security = array('Security question','security',NULL,NULL,NULL);
    
    $error_message = '';
    
    if (!isset($_POST['submit'])) {
    
      showForm();
    
    } else { //form submitted
    
      $error = 0;
      
      if(!empty($_POST['check'])) die("Invalid form access");
      
      if(!empty($_POST['name'])) {
      	$name[2] = clean_var($_POST['name']);
      	if (function_exists('htmlspecialchars')) $name[2] = htmlspecialchars($name[2], ENT_QUOTES);
      }
      else {
        $error = 1;
        $name[3] = 'color:#FF0000;';
      }
      
      if(!empty($_POST['email'])) {
      	$email[2] = clean_var($_POST['email']);
      	if (!validEmail($email[2])) {
      	  $error = 1;
      	  $email[3] = 'color:#FF0000;';
      	  $email[4] = '<strong><span style="color:#FF0000;">Invalid email</span></strong>';
    	  }
      }
      else {
        $error = 1;
        $email[3] = 'color:#FF0000;';
      }
      
      if(!empty($_POST['subject'])) {
      	$subject[2] = clean_var($_POST['subject']);
      	if (function_exists('htmlspecialchars')) $subject[2] = htmlspecialchars($subject[2], ENT_QUOTES);  	
      }
      else {
      	$error = 1;
        $subject[3] = 'color:#FF0000;';
      }  
    
      if(!empty($_POST['message'])) {
      	$message[2] = clean_var($_POST['message']);
      	if (function_exists('htmlspecialchars')) $message[2] = htmlspecialchars($message[2], ENT_QUOTES);
      }
      else {
        $error = 1;
        $message[3] = 'color:#FF0000;';
      }    
    
      if(empty($_POST['security'])) {
        $error = 1;
        $security[3] = 'color:#FF0000;';
      } else {
      	
        if($question_answers[$_POST['question']] != strtolower(clean_var($_POST['security']))) {
          $error = 1;
          $security[3] = 'color:#FF0000;';   
          $security[4] = '<strong><span style="color:#FF0000;">Wrong answer</span></strong>';
        }
      }
    
      if ($error == 1) {
        $error_message = '<span style="font-weight:bold;font-size:90%;">Please correct/enter field(s) in red.</span>';
    
        showForm();
    
      } else {
      	
      	if (function_exists('htmlspecialchars_decode')) $name[2] = htmlspecialchars_decode($name[2], ENT_QUOTES);
      	if (function_exists('htmlspecialchars_decode')) $subject[2] = htmlspecialchars_decode($subject[2], ENT_QUOTES);
      	if (function_exists('htmlspecialchars_decode')) $message[2] = htmlspecialchars_decode($message[2], ENT_QUOTES);  	
      	
        $message = "$name[0]: $name[2]\r\n$email[0]: $email[2]\r\n\r\n$message[0]:\r\n$message[2]\r\n";
        
        if (!$from) $from_value = $email[2];
        else $from_value = $from;
        
       //$headers = "From: $from_value" . "\r\n" . "Reply-To: $email[2]";
    $headers = "From: $from_value\r\nReply-To: $email[2]\r\nBCC: personal_Email@hotmail.com";  
    
        
        mail($to,"$subject_prefix - $subject[2]", $message, $headers);
        
        if (!$thank_you_url) {
        
          include $header_file;
          echo $GLOBALS['thank_you_message'];
          echo "\n";
          include $footer_file;
    	  }
    	  else {
    	  	header("Location: $thank_you_url");
    	  }
           	
      }
    
    } //else submitted
    
    
    
    function showForm()
    
    {
    global $name, $email, $subject, $message, $security, $question_answers, $header_file, $footer_file, $form_width, $form_background, $form_border_color, $form_border_width, $form_border_style, $cell_padding, $left_col_width, $font_size; 
    include $header_file;
    $question = array_rand($question_answers);
    echo $GLOBALS['error_message'];  
    echo <<<EOD
    
    <form method="post" class="cForm">
    <table style="width:{$form_width}; background-color:{$form_background}; border:{$form_border_width} {$form_border_style} {$form_border_color}; padding:10px; font-size:{$font_size};" class="contactForm">
    <tr>
    <td style="width:{$left_col_width}; text-align:left; vertical-align:top; padding:{$cell_padding}; font-weight:bold; {$name[3]}">{$name[0]}</td>
    <td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><input type="text" name="{$name[1]}" value="{$name[2]}" /></td>
    </tr>
    <tr>
    <td style="width:{$left_col_width}; text-align:left; vertical-align:top; padding:{$cell_padding}; font-weight:bold; {$email[3]}">{$email[0]}</td>
    <td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><input type="text" name="{$email[1]}" value="{$email[2]}" /> {$email[4]}</td>
    </tr>
    <tr>
    <td style="width:{$left_col_width}; text-align:left; vertical-align:top; padding:{$cell_padding}; font-weight:bold; {$subject[3]}">{$subject[0]}</td>
    <td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><input type="text" name="{$subject[1]}" value="{$subject[2]}" size="40" /></td>
    </tr>
    <tr>
    <td style="width:{$left_col_width}; text-align:left; vertical-align:top; padding:{$cell_padding}; font-weight:bold; {$message[3]}">{$message[0]}</td>
    <td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><textarea name="{$message[1]}" cols="40" rows="6">{$message[2]}</textarea></td>
    </tr>
    <td style="width:{$left_col_width}; text-align:left; vertical-align:top; padding:{$cell_padding}; font-weight:bold; {$security[3]}">{$question}?</td>
    <td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><input type="text" name="{$security[1]}" value="" size="10" /> {$security[4]}
    <br /><br />We are sorry but please answer the above question to prove you are a real visitor and not a spam bot.</td>
    </tr>
    <tr>
    <td colspan="2" style="text-align:left; vertical-align:middle; padding:{$cell_padding}; font-size:90%; font-weight:bold;">All fields are required.</td>
    </tr>
    <tr>
    <td colspan="2" style="text-align:left; vertical-align:middle; padding:{$cell_padding};"><input type="submit" name="submit" value="Submit" style="border:1px solid #999;background:#E4E4E4;margin-top:5px;" /></td>
    </tr>
    </table>
    <input type="hidden" name="question" value="{$question}">
    <input type="hidden" name="check" value="">
    </form>
    <div style="width:{$form_width};text-align:right;font-size:80%;">
    <a href="http://www.easyphpcontactform.com/" title="PHP Contact Form">PHP Contact Form</a>
    </div> 
    EOD;
    
    include $footer_file;
    }
    
    function clean_var($variable) {
        $variable = strip_tags(stripslashes(trim(rtrim($variable))));
      return $variable;
    }
    
    /**
    Email validation function. Thanks to http://www.linuxjournal.com/article/9585
    */
    function validEmail($email)
    {
       $isValid = true;
       $atIndex = strrpos($email, "@");
       if (is_bool($atIndex) && !$atIndex)
       {
          $isValid = false;
       }
       else
       {
          $domain = substr($email, $atIndex+1);
          $local = substr($email, 0, $atIndex);
          $localLen = strlen($local);
          $domainLen = strlen($domain);
          if ($localLen < 1 || $localLen > 64)
          {
             // local part length exceeded
             $isValid = false;
          }
          else if ($domainLen < 1 || $domainLen > 255)
          {
             // domain part length exceeded
             $isValid = false;
          }
          else if ($local[0] == '.' || $local[$localLen-1] == '.')
          {
             // local part starts or ends with '.'
             $isValid = false;
          }
          else if (preg_match('/\\.\\./', $local))
          {
             // local part has two consecutive dots
             $isValid = false;
          }
          else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
          {
             // character not valid in domain part
             $isValid = false;
          }
          else if (preg_match('/\\.\\./', $domain))
          {
             // domain part has two consecutive dots
             $isValid = false;
          }
          else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local)))
          {
             // character not valid in local part unless 
             // local part is quoted
             if (!preg_match('/^"(\\\\"|[^"])+"$/',
                 str_replace("\\\\","",$local)))
             {
                $isValid = false;
             }
          }
          if ($isValid && function_exists('checkdnsrr'))
          {
          	if (!(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) {
             // domain not found in DNS
             $isValid = false;
           }
          }
       }
       return $isValid;
    }
    
    ?>
    Is there anything obviously wrong?

    Cheers

    Steve

  • #8
    New Coder
    Join Date
    Dec 2009
    Posts
    84
    Thanks
    6
    Thanked 3 Times in 3 Posts
    1st, You should put Please put all your php code between
    PHP Code:
    Your PHP Code Here 
    2nd, You Forgot put <? at the top of your code

    3rd, if you want to know what error, just put
    PHP Code:
    <?php error_reporting(E_ALL); //your next code here...
    4th, after you done all, then talk here what the problem...

    5th.. good luck
    Best Regards,

  • #9
    New Coder
    Join Date
    Dec 2009
    Posts
    84
    Thanks
    6
    Thanked 3 Times in 3 Posts
    1st, if You posted some php code you should put php wrap code between
    PHP Code:
    Your PHP Code Here 
    Please

    2nd, You Forgot put <? at the top of your code

    3rd, if you want to know what error, just put
    PHP Code:
    <?php error_reporting(E_ALL); //your next code here...
    4th, after you done all, then talk here what the problem...

    5th.. good luck
    Best Regards,

  • #10
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    Hello Sir Jones

    Thank you for your post.

    OK, this is what I now have after inserting your line of script:

    [CODE]<?php error_reporting(E_ALL); <----
    //<?php
    session_start();

    $to = 'webMaster@ourSite.com';

    $from = 'webMaster@ourSite.com';

    $subject_prefix = 'Thank you for your enquiry';

    /* Security question and answer array */
    $question_answers = array (
    'Moon is red or white' => 'white',
    'Sun is blue or yellow' => 'yellow',
    'Fire is hot or cold' => 'hot',
    'Icecream is hot or cold' => 'cold'
    );

    /* Form header file */
    $header_file = 'form-header.php';

    /* Form footer file */
    $footer_file = 'form-footer.php';

    /* Form width in px or % value */
    $form_width = '70%';

    /* Form background color */
    $form_background = '#F7F8F7';

    /* Form border color */
    $form_border_color = '#CCCCCC';

    /* Form border width */
    $form_border_width = '1px';

    /* Form border style. Examples - dotted, dashed, solid, double */
    $form_border_style = 'solid';

    /* Form cell padding */
    $cell_padding = '5px';

    /* Form left column width */
    $left_col_width = '25%';

    /* Form font size */
    $font_size = '12px';

    /* Empty/Invalid fields will be highlighted in this color */
    $field_error_color = '#FF0000';

    /* Thank you message to be displayed after the form is submitted. Can include HTML tags. Write your message
    between <!-- Start message --> and <!-- End message --> */
    $thank_you_message = <<<EOD
    <!-- Start message -->
    <p>Thank you for your message. We will contact you within 24 hours.</p><br /><br /><br /><br /><br /><br /><br /><br />
    <!-- End message -->
    EOD;

    /* URL to be redirected to after the form is submitted. If this is specified, then the above message will
    not be shown and user will be redirected to this page after the form is submitted */
    /* Example: $thank_you_url = 'http://www.yourwebsite.com/thank_you.html'; */

    $thank_you_url = '';

    /*******************************************************************************
    * Do not change anything below, unless of course you know very well
    * what you are doing
    *******************************************************************************/

    $name = array('Name','name',NULL,NULL);
    $email = array('Email','email',NULL,NULL,NULL);
    $subject = array('Subject','subject',NULL,NULL);
    $message = array('Message','message',NULL,NULL);
    $security = array('Security question','security',NULL,NULL,NULL);

    $error_message = '';

    if (!isset($_POST['submit'])) {

    showForm();

    } else { //form submitted

    $error = 0;

    if(!empty($_POST['check'])) die("Invalid form access");

    if(!empty($_POST['name'])) {
    $name[2] = clean_var($_POST['name']);
    if (function_exists('htmlspecialchars')) $name[2] = htmlspecialchars($name[2], ENT_QUOTES);
    }
    else {
    $error = 1;
    $name[3] = 'color:#FF0000;';
    }

    if(!empty($_POST['email'])) {
    $email[2] = clean_var($_POST['email']);
    if (!validEmail($email[2])) {
    $error = 1;
    $email[3] = 'color:#FF0000;';
    $email[4] = '<strong><span style="color:#FF0000;">Invalid email</span></strong>';
    }
    }
    else {
    $error = 1;
    $email[3] = 'color:#FF0000;';
    }

    if(!empty($_POST['subject'])) {
    $subject[2] = clean_var($_POST['subject']);
    if (function_exists('htmlspecialchars')) $subject[2] = htmlspecialchars($subject[2], ENT_QUOTES);
    }
    else {
    $error = 1;
    $subject[3] = 'color:#FF0000;';
    }

    if(!empty($_POST['message'])) {
    $message[2] = clean_var($_POST['message']);
    if (function_exists('htmlspecialchars')) $message[2] = htmlspecialchars($message[2], ENT_QUOTES);
    }
    else {
    $error = 1;
    $message[3] = 'color:#FF0000;';
    }

    if(empty($_POST['security'])) {
    $error = 1;
    $security[3] = 'color:#FF0000;';
    } else {

    if($question_answers[$_POST['question']] != strtolower(clean_var($_POST['security']))) {
    $error = 1;
    $security[3] = 'color:#FF0000;';
    $security[4] = '<strong><span style="color:#FF0000;">Wrong answer</span></strong>';
    }
    }

    if ($error == 1) {
    $error_message = '<span style="font-weight:bold;font-size:90%;">Please correct/enter field(s) in red.</span>';

    showForm();

    } else {

    if (function_exists('htmlspecialchars_decode')) $name[2] = htmlspecialchars_decode($name[2], ENT_QUOTES);
    if (function_exists('htmlspecialchars_decode')) $subject[2] = htmlspecialchars_decode($subject[2], ENT_QUOTES);
    if (function_exists('htmlspecialchars_decode')) $message[2] = htmlspecialchars_decode($message[2], ENT_QUOTES);

    $message = "$name[0]: $name[2]\r\n$email[0]: $email[2]\r\n\r\n$message[0]:\r\n$message[2]\r\n";

    if (!$from) $from_value = $email[2];
    else $from_value = $from;

    //$headers = "From: $from_value" . "\r\n" . "Reply-To: $email[2]";
    $headers = "From: $from_value\r\nReply-To: $email[2]\r\nBCC: personal_Email@hotmail.com";


    mail($to,"$subject_prefix - $subject[2]", $message, $headers);

    if (!$thank_you_url) {

    include $header_file;
    echo $GLOBALS['thank_you_message'];
    echo "\n";
    include $footer_file;
    }
    else {
    header("Location: $thank_you_url");
    }

    }

    } //else submitted



    function showForm()

    {
    global $name, $email, $subject, $message, $security, $question_answers, $header_file, $footer_file, $form_width, $form_background, $form_border_color, $form_border_width, $form_border_style, $cell_padding, $left_col_width, $font_size;
    include $header_file;
    $question = array_rand($question_answers);
    echo $GLOBALS['error_message'];
    echo <<<EOD

    <form method="post" class="cForm">
    <table style="width:{$form_width}; background-color:{$form_background}; border:{$form_border_width} {$form_border_style} {$form_border_color}; padding:10px; font-size:{$font_size};" class="contactForm">
    <tr>
    <td style="width:{$left_col_width}; text-align:left; vertical-align:top; padding:{$cell_padding}; font-weight:bold; {$name[3]}">{$name[0]}</td>
    <td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><input type="text" name="{$name[1]}" value="{$name[2]}" /></td>
    </tr>
    <tr>
    <td style="width:{$left_col_width}; text-align:left; vertical-align:top; padding:{$cell_padding}; font-weight:bold; {$email[3]}">{$email[0]}</td>
    <td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><input type="text" name="{$email[1]}" value="{$email[2]}" /> {$email[4]}</td>
    </tr>
    <tr>
    <td style="width:{$left_col_width}; text-align:left; vertical-align:top; padding:{$cell_padding}; font-weight:bold; {$subject[3]}">{$subject[0]}</td>
    <td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><input type="text" name="{$subject[1]}" value="{$subject[2]}" size="40" /></td>
    </tr>
    <tr>
    <td style="width:{$left_col_width}; text-align:left; vertical-align:top; padding:{$cell_padding}; font-weight:bold; {$message[3]}">{$message[0]}</td>
    <td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><textarea name="{$message[1]}" cols="40" rows="6">{$message[2]}</textarea></td>
    </tr>
    <td style="width:{$left_col_width}; text-align:left; vertical-align:top; padding:{$cell_padding}; font-weight:bold; {$security[3]}">{$question}?</td>
    <td style="text-align:left; vertical-align:top; padding:{$cell_padding};"><input type="text" name="{$security[1]}" value="" size="10" /> {$security[4]}
    <br /><br />We are sorry but please answer the above question to prove you are a real visitor and not a spam bot.</td>
    </tr>
    <tr>
    <td colspan="2" style="text-align:left; vertical-align:middle; padding:{$cell_padding}; font-size:90%; font-weight:bold;">All fields are required.</td>
    </tr>
    <tr>
    <td colspan="2" style="text-align:left; vertical-align:middle; padding:{$cell_padding};"><input type="submit" name="submit" value="Submit" style="border:1px solid #999;background:#E4E4E4;margin-top:5px;" /></td>
    </tr>
    </table>
    <input type="hidden" name="question" value="{$question}">
    <input type="hidden" name="check" value="">
    </form>
    <div style="width:{$form_width};text-align:right;font-size:80%;">
    <a href="http://www.easyphpcontactform.com/" title="PHP Contact Form">PHP Contact Form</a>
    </div>
    EOD;

    include $footer_file;
    }

    function clean_var($variable) {
    $variable = strip_tags(stripslashes(trim(rtrim($variable))));
    return $variable;
    }

    /**
    Email validation function. Thanks to http://www.linuxjournal.com/article/9585
    */
    function validEmail($email)
    {
    $isValid = true;
    $atIndex = strrpos($email, "@");
    if (is_bool($atIndex) && !$atIndex)
    {
    $isValid = false;
    }
    else
    {
    $domain = substr($email, $atIndex+1);
    $local = substr($email, 0, $atIndex);
    $localLen = strlen($local);
    $domainLen = strlen($domain);
    if ($localLen < 1 || $localLen > 64)
    {
    // local part length exceeded
    $isValid = false;
    }
    else if ($domainLen < 1 || $domainLen > 255)
    {
    // domain part length exceeded
    $isValid = false;
    }
    else if ($local[0] == '.' || $local[$localLen-1] == '.')
    {
    // local part starts or ends with '.'
    $isValid = false;
    }
    else if (preg_match('/\\.\\./', $local))
    {
    // local part has two consecutive dots
    $isValid = false;
    }
    else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
    {
    // character not valid in domain part
    $isValid = false;
    }
    else if (preg_match('/\\.\\./', $domain))
    {
    // domain part has two consecutive dots
    $isValid = false;
    }
    else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local)))
    {
    // character not valid in local part unless
    // local part is quoted
    if (!preg_match('/^"(\\\\"|[^"])+"$/',
    str_replace("\\\\","",$local)))
    {
    $isValid = false;
    }
    }
    if ($isValid && function_exists('checkdnsrr'))
    {
    if (!(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) {
    // domain not found in DNS
    $isValid = false;
    }
    }
    }
    return $isValid;
    }

    ?>[/CODE]

    I do not get any errors through your line of code and the form appears to be sent correctly, but I have just filled in the form and nothing has arrived. Maybe I should wait longer - there is nothing in the script, is there, to explain a time delay on receiving the email?

    Thanks, Sir Jones!

    Steve


  •  

    Posting Permissions

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