Конвертировать php X-mailer в smtp почту

Мне нужна помощь в преобразовании моего кода из экземпляра X-mailer php в сценарий SMTP, который входит в систему и отправляет электронную почту, но я должен сохранить введенные поля проверки и проверки. вы заметите, что одна отправка отправляет 2 несколько разных электронных письма, а третья - если поле $alt_email заполнено правильно. $email_from2 и $email_to всегда кодируются, а все остальные поля передаются из предыдущей HTML-формы.

<?php
if(isset($_POST['prob_email'])) {

         $email_from2 = "source@domain.com";   // NAME OF FORM SOURCE 
         $email_to = "destination@domain.com";    // DESTINATION
         $userip = ($_SERVER['X_FORWARDED_FOR']) ? $_SERVER['X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];

         function died($error) {                
            echo "There are error(s) found with the form you submitted. ";        
            echo "These errors appear below.<br /><br />";        
            echo $error."<br /><br />";        
            echo "Please hit back in your browser to fix these errors.<br /><br />";                
            die();    
         }         

         // REQUIRED FIELDS   
         if(!isset($_POST['prob_email']) ||        
            !isset($_POST['first_name']) ||        
            !isset($_POST['last_name']) ||        
            !isset($_POST['phone']) ||
            !isset($_POST['prob_desc'])) {        
            died('There appears to be a problem with the form you submitted.');           
         }         
         // ALL FIELDS
         $email_from = $_POST['prob_email'];
         $first_name = $_POST['first_name'];   
         $last_name = $_POST['last_name']; 
         $phone = $_POST['phone'];
         $alt_email = $_POST['alt_email'];
         $fax = $_POST['fax'];
         $weekdays = $_POST['weekdays'];
         $after_hours = $_POST['after_hours'];
         $weekends = $_POST['weekends']; 
         $prob_desc = $_POST['prob_desc'];

         //FIELD CHECKING        
         $error_message = "";    
         $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; // valid email address
         $names_exp = '/^[A-Za-z]+$/';  // only letters, upper and lower
         $phones_exp = '/^[0-9]{3}+[-]{1}+[0-9]{3}+[-]{1}+[0-9]{4}$/';  // phone numbers as 000-000-0000 only          
         $pwd_exp = '/^(?=[^\d_].*?\d)(?=.*\d)(?=.*[a-zA-Z])(?!.*[\W_\x7B-\xFF]).{8,20}$/';    // /^([A-Za-z]{1})(?=.*\d)(?=.*[a-zA-Z])(?!.*[\W_\x7B-\xFF]).{8,20}$/               
       if(!preg_match($email_exp,$email_from)) {    
         $error_message .= 'The Problem Email Address you entered does not appear to be valid.<br />';  
       }
       if(strlen($alt_email) > 0) {    // makes field optional
         if(!preg_match($email_exp,$alt_email)) { 
         $error_message .= 'The Alternate Email Address you entered does not appear to be valid.<br />';
       }}        
       if(!preg_match($names_exp,$first_name)) {    
         $error_message .= 'The First Name you entered does not appear to be valid.<br />';  
       }  
       if(!preg_match($names_exp,$last_name)) {    
         $error_message .= 'The Last Name you entered does not appear to be valid.<br />';  
       }  
       if(!preg_match($phones_exp,$phone)) {    
         $error_message .= 'The Phone # you entered does not appear to be valid.<br /><span style="color:#FFF">-----</span>Phone # must be formatted as 000-000-0000<br />'; 
       }
       if(strlen($weekdays) < 3) {
         if(strlen($after_hours) < 3) {
           if(strlen($weekends) < 3) {
         $error_message .= 'You must select at least one contact time option.<br />'; 
       }}}
       if(strlen($fax) > 0) { // makes field optional
         if(!preg_match($phones_exp,$fax)) {    
         $error_message .= 'The Fax # you entered does not appear to be valid.<br /><span style="color:#FFF">-----</span>Fax # must be formatted as 000-000-0000<br />'; 
       }}
       if(strlen($prob_desc) < 5) {    // at least 5 char. required
         $error_message .= 'The Problem Description you entered does not appear to be valid.<br />'; 
       }  
       if(strlen($error_message) > 0) {    
         died($error_message);  
       }    
         $email_message = "Form details below. (BLANK ANSWER = no answer entered)\n\n";
         $email_message .= "\n";         
         function clean_string($string) {      
           $bad = array("content-type","bcc:","to:","cc:","href");               
           return str_replace($bad,"",$string);    
         }         
         // OUTPUT
         $email_message .= "Do NOT reply directly to this automated email, instead direct any further correspondence again through our SUPPORT FORM or via reply to our upcoming separate response\n\n";
         $email_message .= "\n";
         $email_message .= "Problem Email: ".clean_string($email_from)."\n";             
         $email_message .= "\n";
         $email_message .= "First Name: ".clean_string($first_name)."\n";             
         // $email_message .= "\n";
         $email_message .= "Last Name: ".clean_string($last_name)."\n"; 
         $email_message .= "\n";
         $email_message .= "Phone: ".clean_string($phone)."\n";
         // $email_message .= "\n";
         $email_message .= "Alternate Email: ".clean_string($alt_email)."\n";
         // $email_message .= "\n";
         $email_message .= "Fax: ".clean_string($fax)."\n";
         $email_message .= "\n";
         $email_message .= "contact on weekdays: ".clean_string($weekdays)."\n";
         // $email_message .= "\n";
         $email_message .= "contact after hours: ".clean_string($after_hours)."\n";
         // $email_message .= "\n";
         $email_message .= "contact on weekends: ".clean_string($weekends)."\n";
         $email_message .= "\n";
         $email_message .= "problem description: ".clean_string($prob_desc)."\n";
         $email_message .= "\n";
         $email_message .= "Request was sent from the IP address: ".clean_string($userip)."\n\n";
         $email_message .= "\n";


// EMAIL TO DESTINATION          
$email_subject = "SUPPORT FORM for account ".$email_from;
$headers = 'From: '.$email_from2."\r\n".
'Reply-To: '.$email_from2."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  

// EMAIL COPY TO SENDER
$email_subject = "your copy of Webmail Support Form from ".$email_from;
$headers = 'From: '.$email_from2."\r\n".
'Reply-To: '.$email_from2."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_from, $email_subject, $email_message, $headers);  

// EMAIL COPY TO ALT SENDER
$email_subject = "your copy of Webmail Support Form from ".$email_from;
$headers = 'From: '.$email_from2."\r\n".
'Reply-To: '.$email_from2."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($alt_email, $email_subject, $email_message, $headers);  

// SUCCESS PAGE
?> 

<?php
{ $url = 'success.html"';
    echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; }}
?>

0 ответов

Другие вопросы по тегам