Location: PHPKode > scripts > Fast Secure Contact Form > fscf-contact-form/contact-files/admin/contact-form-do-test-mail.php
<?php
/*
Fast Secure Contact Form - PHP Script
Author: Mike Challis
http://www.FastSecureContactForm.com/
*/
//do not allow direct access
if ( strpos(strtolower($_SERVER['SCRIPT_NAME']),strtolower(basename(__FILE__))) ) {
 header('HTTP/1.0 403 Forbidden');
 exit('Forbidden');
}

       // Send test mail

       // new lines should be (\n for UNIX, \r\n for Windows and \r for Mac)
       //$php_eol = ( strtoupper(substr(PHP_OS,0,3) == 'WIN') ) ? "\r\n" : "\n";

	   $php_eol = (!defined('PHP_EOL')) ? (($eol = strtolower(substr(PHP_OS, 0, 3))) == 'win') ? "\r\n" : (($eol == 'mac') ? "\r" : "\n") : PHP_EOL;
	   $php_eol = (!$php_eol) ? "\n" : $php_eol;

	   $email = $_POST['fsc_to'];
       $name = _('Contact Form Test');
       if($this->ctf_validate_email($email)) {

		  $subject = _('Test mail to ') . $email;
		  $message = _('This is a test mail generated by the Fast Secure Contact Form PHP script.').' '.sprintf(_('Sent with %s'),$fsc_opt['php_mailer_enable']).'.';
          $message = wordwrap($message, 70,$php_eol);

          $smtp_debug = '';
          $ctf_email_on_this_domain =  $fsc_opt['email_from']; // optional
          // prepare the email header
          $this->fsc_from_name = $name;
          $this->fsc_from_email = $email;
          if ($ctf_email_on_this_domain != '' ) {
              if(!preg_match("/,/", $ctf_email_on_this_domain)) {
                // just an email: hide@address.com
                $this->fsc_mail_sender = $ctf_email_on_this_domain;
                if($email == '' || $fsc_opt['email_from_enforced'] == 'true')
                   $this->fsc_from_email = $ctf_email_on_this_domain;
              } else {
                // name and email: webmaster,hide@address.com
                list($key, $value) = explode(",",$ctf_email_on_this_domain);
                $key   = trim($key);
                $value = trim($value);
                $this->fsc_mail_sender = $value;
                if($name == '')
                  $this->fsc_from_name = $key;
                if($email == '' || $fsc_opt['email_from_enforced'] == 'true')
                  $this->fsc_from_email = $value;
              }
         }
         $header_php =  "From: $this->fsc_from_name <$this->fsc_from_email>\n"; // header for php mail only
         $header = '';
         if ($fsc_opt['email_reply_to'] != '') { // custom reply_to
              $header .= "Reply-To: ".$fsc_opt['email_reply_to']."\n"; // for php mail and wp_mail
         }else if($email != '') {   // trying this: keep users reply to even when email_from_enforced
              $header .= "Reply-To: $email\n"; // for php mail and wp_mail
         }else {
              $header .= "Reply-To: $this->fsc_from_email\n"; // for php mail and wp_mail
         }
         if ($ctf_email_on_this_domain != '') {
           $header .= "X-Sender: $this->fsc_mail_sender\n";  // for php mail
           $header .= "Return-Path: $this->fsc_mail_sender\n";   // for php mail
         }
         $header .= 'Content-type: text/plain; charset='. $fsc_site['site_charset'] . $php_eol;

         @ini_set('sendmail_from', $this->fsc_from_email);

         // Check for safe mode
         $this->safe_mode = ((boolean)@ini_get('safe_mode') === false) ? 0 : 1;

         if ($fsc_opt['php_mailer_enable'] == 'php') {
            // sending with php mail
            $header_php .= $header;
            // Start output buffering to grab smtp debugging output
	        ob_start();
            if ($ctf_email_on_this_domain != '' && !$this->safe_mode) {
                // Pass the Return-Path via sendmail's -f command.
                $result = mail($email,$subject,$message,$header_php, '-f '.$this->fsc_mail_sender);
            }else{
                // the fifth parameter is not allowed in safe mode
                $result = mail($email,$subject,$message,$header_php);
            }
            $smtp_debug = ob_get_clean();
         }else if ($fsc_opt['php_mailer_enable'] == 'phpmailer') {

           require_once $this->site_path . '/phpmailer5/class.phpmailer.php';
           $phpmailer = new PHPMailer ();
		   $phpmailer->SMTPDebug = 2;
           // Start output buffering to grab smtp debugging output
		   ob_start();

           $phpmailer->From = $this->fsc_from_email;
           $phpmailer->FromName = $this->fsc_from_name;
           $phpmailer->AddAddress($email);
           if ($fsc_opt['email_reply_to'] != '') { // custom reply_to
               $phpmailer->AddReplyTo($fsc_opt['email_reply_to']);
           }else if($email != '') {   // trying this: keep users reply to even when email_from_enforced
               $phpmailer->AddReplyTo($email);
           }else {
               $phpmailer->AddReplyTo($this->fsc_from_email);
           }
           $phpmailer->CharSet = $fsc_site['site_charset'];
           $phpmailer->Subject = $subject;
           $phpmailer->Body = $message;
           if ( substr($fsc_site['language'], 0, 2) != '' ) {
             $phpmailer->SetLanguage(substr($fsc_site['language'], 0, 2), $this->site_path . '/phpmailer5/');
           }
           //$phpmailer->IsHTML(true);

           if ($fsc_opt['smtp_enable'] == 'true') {
             $phpmailer->IsSMTP();  // Set to use SMTP
             $phpmailer->Host = $fsc_opt['smtp_host']; // smtp.gmail.com
             $phpmailer->SMTPSecure = $fsc_opt['smtp_encryption'];  // encryption: ssl or tls or ''
             $phpmailer->Port = $fsc_opt['smtp_port']; // 25 or 465
             if ($fsc_opt['smtp_auth_enable'] == 'true') {
               $phpmailer->SMTPAuth = true; // if must have user : pass
               $phpmailer->Username = $fsc_opt['smtp_user'];
               $phpmailer->Password = $fsc_opt['smtp_pass'];
             }
           }else{
               $phpmailer->IsMail(); // Set to use PHP's mail()
           }

         // Set custom headers
         if ($ctf_email_on_this_domain != '') {
           // add Sender for Return-path
           $phpmailer->Sender = $this->fsc_mail_sender;
           $phpmailer->AddCustomHeader("X-Sender: $this->fsc_mail_sender");
         }

        $result = @$phpmailer->Send();

        // Grab the smtp debugging output
		$smtp_debug = ob_get_clean();

         }
		 // Output the response
		?>
<div class="updated"><p><strong><?php
echo _('Test Message Sent');
echo '<br />'.$subject; ?></strong></p>
<?php   if ($result != true) { ?>
<p><?php    echo _('The result was:'); ?></p>
<pre><?php  var_dump($result); ?></pre>
<?php
        } else {
            echo '<p>'.sprintf(_('Sent with %s'),$fsc_opt['php_mailer_enable']).'. '. _('Be sure to check your email to see if you received it.').'</p>';
            echo '<p><a href="http://www.fastsecurecontactform.com/email-does-not-send">'.  _('See FAQ') . '</a></p>';
        }
      if ($result != true && $smtp_debug != '') {
?>
<p><?php echo _('The E-mail debugging output is shown below:'); ?></p>
<?php echo '<p><a href="http://www.fastsecurecontactform.com/email-does-not-send">'.  _('See FAQ') . '</a></p>'; ?>
<pre><?php echo $smtp_debug ?></pre>
<?php }

   }else{ // end if validate mail
     echo '<div class="error"><strong>'._('Test failed: Invalid E-mail address').'</strong>';
   }
?>
</div>
<?php

?>
Return current item: Fast Secure Contact Form