How to modify php form processing script for localhost

weknowjack
weknowjack used Ask the Experts™
on
I manage a site that has an MX pointing to a remote server for email.

Problem: A form on the web site is intermittantly not sending mail to the form owner from the site. I think the issue might be the remote email server at the former hosting service.

Until we can move these emails over to the web host's server, I am told I can make a change in the php processor for the form to add localhost that makes the email send through the site host server. If this is true, how and where would I do that? I do not write php.

Or if there is a better solution, what would that be? Here is the current processor. I deleted commented out code and changed stuff for security purposes:

<?

include("./wp-config.php");

$frm_server_side_error="";

$error="";

function check_email($email){

      $Result = eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);

      if ($Result)

            return TRUE;

      else

            return FALSE;

}

function check_text($textbox){      

      if ((trim($textbox) != "")){

            return true;

      }      

      else{

            return false;

      }            

}

function check_integer($int){

      $Result = eregi("^[0-9]*$", $int);

      if ($Result)

            return TRUE;

      else

            return FALSE;

}      



if(isset($_REQUEST[sendbutton])){

   $frm_path = $_REQUEST[frm_path];

   $first_name = $_REQUEST[cf_field_2];

   $last_name = $_REQUEST[frm_last];

   $email = $_REQUEST[cf_field_3];

   $phone1 = $_REQUEST[frm_phone1];

   $phone2 = $_REQUEST[frm_phone2];

   $phone3 = $_REQUEST[frm_phone3];

   $phone = $phone1."-".$phone2."-".$phone3;

   

   

  $move_in_date = $_REQUEST[cf_field_6];

   

 

         if(!check_text($_REQUEST[cf_field_2])){

                  $frm_server_side_error = "First Name,";

            }      

          if(!check_text($_REQUEST[frm_phone1])){

                  $frm_server_side_error = $frm_server_side_error."Phone1,";      

            }else{

               if(!check_integer($_REQUEST[frm_phone1])){

                 $frm_server_side_error = $frm_server_side_error."Phone1,";

               }

            }

            

            if(!check_text($_REQUEST[frm_phone2])){

                  $frm_server_side_error = $frm_server_side_error."Phone2,";      

            }else{

               if(!check_integer($_REQUEST[frm_phone2])){

                 $frm_server_side_error = $frm_server_side_error."Phone2,";

               }

            }

            if(!check_text($_REQUEST[frm_phone3])){

                  $frm_server_side_error = $frm_server_side_error."Phone3,";      

            }else{

               if(!check_integer($_REQUEST[frm_phone3])){

                 $frm_server_side_error = $frm_server_side_error."Phone1,";

               }

            }

            if(!check_text($email)){

                     $frm_server_side_error.='Email,';

                     $flag = true;       

          }

            if(check_text($email)){

                  if(!check_email($email)){

                         $frm_server_side_error = $frm_server_side_error."Email,";

                  }

            }

      

   $count=30;

   for($i=0;$i<=$count;$i++){

            if(!$_POST[cf_field_7][$i] == ""){

                  $edit_check_city.= $_POST[cf_field_7][$i].",";

            }

      }            

   $lease_term = $_REQUEST[cf_field_8];

   $bedrooms = $_REQUEST[cf_field_9];

   $bath_rooms = $_REQUEST[cf_field_10];

   $max_rent = $_REQUEST[cf_field_11];

   $count_am=24;

   for($k=0;$k<=$count_am;$k++){

            if(!$_POST[cf_field_12][$k] == ""){

                  $edit_check_amenity.= $_POST[cf_field_12][$k].",";

            }

      }            

   

   $additional_notes = $_REQUEST[cf_field_13];

   

   if($frm_server_side_error==""){

            $sql_email_check = "select * from tbl_search_details where str_email ='$email'";

            $rs_email_check = mysql_query($sql_email_check);

                         

             if(mysql_num_rows($rs_email_check)<1){

                  header("Location: http://www.domain/folder");

             }else{      

                        $sql_insert= "insert into tbl_search_details ( str_first_name , str_last_name, str_email , str_phone , str_movein_date , bit_active ) values ('$first_name', '$last_name', '$email', '$phone', '$move_in_date','1')";

                      $rs_insert = mysql_query($sql_insert) or die(mysql_error());

                      $today = date("Y-m-d");

                        list($job_year,$job_month,$job_day)=split("-", $today);

                        $month = date(M,mktime(0,0,0,$job_month,$job_day,$job_year));

                    $ip = $_SERVER['REMOTE_ADDR'];

                        $mail_to = "email1@gmail.com,email2@email.com";

                        $mail_subject= "User Registration from Site ";

                        $mail_body = "<table style=font:Verdana; font-size:10px;  border=0 cellspacing=0 cellpadding=2 width=700><tr ><td height=25 colspan=2 style='color:#7d7d7d;font-family:tahoma;font-size:13px;' align='right'>a form has been submitted on $month $job_day, $job_year via: /contact[IP $ip]</td></tr></table>";

                        $mail_body = $mail_body ."<table style=font:Verdana; font-size:10px;  border=0 cellspacing=0 cellpadding=1 width=700><tr bgcolor=#eff0fa><td height=25 colspan=2 style='color:#7d7d7d;font-family:tahoma;font-size:13px;'>BEGIN YOUR FREE SEARCH</td></tr>";

                        $mail_body = $mail_body ."<tr bgcolor=#e6e8f7><td height=1 colspan=2></td></tr><tr bgcolor=#f4f5fb><td style='font-family:arial,tahoma;font-size:12px;color=#6c6c6c;' width=30%'>";

                        $mail_body = $mail_body ."Name:</td><td style='font-family:arial,tahoma;font-size:12px;color:#7d7d7d;' width=70%>$first_name $last_name</td></tr>";

                        $mail_body = $mail_body ."<tr bgcolor=#f4f5fb><td style='font-family:arial,tahoma;font-size:12px;color=#6c6c6c;' height=25>Email:</td><td style='font-family:arial,tahoma;font-size:12px;color:#7d7d7d;'>$email</td></tr>";

                        $mail_body = $mail_body ."<tr bgcolor=#f4f5fb><td style='font-family:arial,tahoma;font-size:12px;color=#6c6c6c;' height=25>Phone:</td><td style='font-family:arial,tahoma;font-size:12px;color:#7d7d7d;'>$phone</td></tr>";

                        $mail_body = $mail_body ."<tr bgcolor=#f4f5fb><td style='font-family:arial,tahoma;font-size:12px;color=#6c6c6c;' height=25>Move In Date:</td><td style='font-family:arial,tahoma;font-size:12px;color:#7d7d7d;'>$move_in_date</td></tr>";

                        $mail_body = $mail_body ."<tr bgcolor=#f4f5fb><td style='font-family:arial,tahoma;font-size:12px;color=#6c6c6c;' height=25>Preferred Cities:</td><td style='font-family:arial,tahoma;font-size:12px;color:#7d7d7d;'>$edit_check_city</td></tr>";

                        $mail_body = $mail_body ."<tr bgcolor=#f4f5fb><td style='font-family:arial,tahoma;font-size:12px;color=#6c6c6c;' height=25>Lease Term:</td><td style='font-family:arial,tahoma;font-size:12px;color:#7d7d7d;'>$lease_term</td></tr>";

                        $mail_body = $mail_body ."<tr bgcolor=#f4f5fb><td style='font-family:arial,tahoma;font-size:12px;color=#6c6c6c;' height=25>Bedrooms:</td><td style='font-family:arial,tahoma;font-size:12px;color:#7d7d7d;'>$bedrooms</td></tr>";

                        $mail_body = $mail_body ."<tr bgcolor=#f4f5fb><td style='font-family:arial,tahoma;font-size:12px;color=#6c6c6c;' height=25>Bathrooms:</td><td style='font-family:arial,tahoma;font-size:12px;color:#7d7d7d;'>$bath_rooms</td></tr>";

                        $mail_body = $mail_body ."<tr bgcolor=#f4f5fb><td style='font-family:arial,tahoma;font-size:12px;color=#6c6c6c;' height=25>Max Rent:</td><td style='font-family:arial,tahoma;font-size:12px;color:#7d7d7d;'>$max_rent</td></tr>";

                        $mail_body = $mail_body ."<tr bgcolor=#f4f5fb><td style='font-family:arial,tahoma;font-size:12px;color=#6c6c6c;' height=25>Desired Amenities:</td><td style='font-family:arial,tahoma;font-size:12px;color:#7d7d7d;'>$edit_check_amenity</td></tr>";

                        $mail_body = $mail_body ."<tr bgcolor=#f4f5fb><td style='font-family:arial,tahoma;font-size:12px;color=#6c6c6c;' height=25>Additional Notes:</td><td style='font-family:arial,tahoma;font-size:12px;color:#7d7d7d;'>$additional_notes</td></tr>";

                        $mail_body = $mail_body ."<tr bgcolor=#f4f5fb><td style='font-family:arial,tahoma;font-size:12px;color=#6c6c6c;' height=25>Referrel URL:</td><td style='font-family:arial,tahoma;font-size:12px;color:#7d7d7d;'>$frm_path</td></tr>";

                        $mail_body = $mail_body ."</td></tr><tr><td align='left'><br><a href='http://www.domain.com'>www.domain.com</a></td></tr></table>";

                        $headers =  "Content-Type: text/html;charset=iso-8859-1\n";

                        $headers = $headers . "From:".$email."";

                        //die($mail_body);

                        mail($mail_to,$mail_subject,$mail_body,$headers);

                        header("Location: http://www.domain.com/folder");

                  }
   }

}?>
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
PHP's mail() function, gets it's path from php.ini. You'll have to check the sendmail_path = /usr/sbin/sendmail setting in that config file.

But It's unusual for sendmail to be using a remote server...

You could sign up for a free hosting account with anyone that offers one and put a script on there to send the emails, it'll use that server's sendmail and won't have a problem. As a temporary measure of course.

Author

Commented:
The path is currently

"/usr/sbin/sendmail -t -i"

Would I make changes to that for localhost?

I'm really in the dark here about how to do something like this without screwing things up.

Thanks
Most Valuable Expert 2011
Top Expert 2016

Commented:
Consider using a service for this kind of thing.  Look at Constant Contact (and their competitors).  Costs are nominal and tech support is usually very good.  Best, ~Ray

Author

Commented:
The solution turned out to be the advice of  I-CONICA  in this post:

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/Q_26305504.html

I'm not sure how to apply points here, because the problem I presented here was actually not the problem.




Author

Commented:
I had incorrectly applied I-CONICA's previous fix, which prompted this question.
After experimentation, neither solution was acceptable. I had to have someone fix the issue.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial