Jump to content

PHP Parse error: syntax error, unexpected T_STRING


phpnewbieca

Recommended Posts

I need some help. I received this error:

 

PHP Parse error:  syntax error, unexpected T_STRING in on line 33

 

Line 33:  $fh = fopen("$MyFile", "r");

 

I read everything I could on this error but nothing applies to my situation.

 

 

<?php
 // Process valid_repair_upgradeform 
 error_reporting(-1);
 //Define Variable(s)
 $date = date("D  d M Y - H:i:s ");
 $my_file = "s_vcs.txt";
 $my_path = $_SERVER['DOCUMENT_ROOT']."/home/users/web/b686/dom.horacela/public_html/";
 $my_name = "Newbieca";
 $my_mail = "[email protected]";
 $my_replyto = "[email protected]";
 $my_subject = "Order Validated";
 $my_message = "This order was validated Confirmation Number: $confirmation_number on Date: $date.\r\n\r\n";
 if (is_writable($my_file)) {
    echo " ";
 } else {
    echo 'The file is not writable\n\n';
 }
 if (is_readable($my_file)) {
    echo " ";
 } else {
    echo 'The file is not readable';
 }
 //Get Data From Form
 $Confirmation_number = $_POST['Confirmation_number'];
 // validate expected data exists 
 if(!isset($_POST['Confirmation_number'])) {
  echo "No Confirmation_number.\n";
  die();
 }
 // Search fille for Confirmation_number. If found call function 
 $MyFile = "s_vcs.txt";
 $searchfor = $Confirmation_number;
 $fh = fopen("$MyFile", "r");
 $olddata = fread($fh, filesize($MyFile));
 if(strpos($olddata, "$searchfor")) {
  echo "fount it";
  // Call Functions
  mail_attachment($my_file, $my_path, "[email protected]", $my_mail, $my_name, $my_replyto, $my_subject, $my_message);
 }
 else {
  echo "can't find it";
 }
 fclose($fh);
 //FUNCTION(S) 
 function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
  $file = $path.$filename;
  $file_size = filesize($file);
  $handle = fopen($file,"r");
  $content = fread($handle,$file_size);
  fclose($handle);
  $content = chunk_split(base64_encode($content));
  $uid = md5(uniqid(time()));
  $name = basename($file);
  $header = "From: ".$from_name." <".$from_mail.">\r\n";
  $header .= "Reply-To: ".$replyto."\r\n";
  $header .= "MIME-Version: 1.0\r\n";
  $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
  $header .= "This is a multi-part message in MIME format.\r\n";
  $header .= "--".$uid."\r\n";
  $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
  $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
  $header .= $message."\r\n\r\n";
  $header .= "--".$uid."\r\n";
  $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
  $header .= "Content-Transfer-Encoding: base64\r\n";
  $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
  $header .= $content."\r\n\r\n";
  $header .= "--".$uid."--";
  if (mail($mailto, $subject, "", $header)) {
      echo "mail send ... OK"; // or use booleans here
  } else {
      echo "mail send ... ERROR!";
  }
 }
?>
 

Sleepy Member: I retyped the line.

Newbie: I took the quotes off.

 

and got this error:

PHP Parse error:  syntax error, unexpected T_STRING in on line 35 
Line 35:  if(strpos($olddata, "$searchfor")) {
 
So, I took the quotes off:
if(strpos($olddata, $searchfor)) {
 
Then I received 'can't find it'. That is line 41:   echo "can't find it";
 
The confirmation Number is in $MyFile: Confirmation Number: 905915307
 
Any Ideas why it cant find the confirmation number '905915307 '?
 

<?php
 // Process valid_repair_upgradeform 
 error_reporting(-1);
 //Define Variable(s)
 $date = date("D  d M Y - H:i:s ");
 $my_file = "s_vcs.txt";
 $my_path = $_SERVER['DOCUMENT_ROOT']."/home/users/web/b686/dom.horacela/public_html/";
 $my_name = "Newbieca";
 $my_mail = "[email protected]";
 $my_replyto = "[email protected]";
 $my_subject = "Order Validated";
 $my_message = "This order was validated Confirmation Number: $confirmation_number on Date: $date.\r\n\r\n";
 if (is_writable($my_file)) {
    echo " ";
 } else {
    echo 'The file is not writable\n\n';
 }
 if (is_readable($my_file)) {
    echo " ";
 } else {
    echo 'The file is not readable';
 }
 //Get Data From Form
 $confirmation_number = $_POST['confirmation_number'];
 // validate expected data exists 
 if(!isset($_POST['confirmation_number'])) {
  echo "No Confirmation_number.\n";
  die();
 }
 // Search file for Confirmation_number. If found call function 
 $MyFile = "s_vcs.txt";
 $searchfor = $confirmation_number;
 $fh = fopen(MyfFile, "r");
 $olddata = fread($fh, filesize($MyFile));
 if(strpos($olddata, $searchfor)) {
  echo "fount it";
  // Call Functions
  mail_attachment($my_file, $my_path, "[email protected]", $my_mail, $my_name, $my_replyto, $my_subject, $my_message);
 }
 else {
  echo "can't find it";
 }
 fclose($fh);
 //FUNCTION(S) 
 function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
  $file = $path.$filename;
  $file_size = filesize($file);
  $handle = fopen($file,"r");
  $content = fread($handle,$file_size);
  fclose($handle);
  $content = chunk_split(base64_encode($content));
  $uid = md5(uniqid(time()));
  $name = basename($file);
  $header = "From: ".$from_name." <".$from_mail.">\r\n";
  $header .= "Reply-To: ".$replyto."\r\n";
  $header .= "MIME-Version: 1.0\r\n";
  $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
  $header .= "This is a multi-part message in MIME format.\r\n";
  $header .= "--".$uid."\r\n";
  $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
  $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
  $header .= $message."\r\n\r\n";
  $header .= "--".$uid."\r\n";
  $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
  $header .= "Content-Transfer-Encoding: base64\r\n";
  $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
  $header .= $content."\r\n\r\n";
  $header .= "--".$uid."--";
  if (mail($mailto, $subject, "", $header)) {
      echo "mail send ... OK"; // or use booleans here
  } else {
      echo "mail send ... ERROR!";
  }
 }
?>

Quote

Hi. Maybe you can try utting the xml tag in the first line of your file.

 

Please explain how the XML tag would help?

Nothing I have read indicates the XML would be of use in this script.

a. http://en.wikipedia.org/wiki/XML

b. http://www.tizag.com/xmlTutorial/xmltag.php

c. http://php.net/manual/en/language.basic-syntax.php  

The string $searchfor has this in it: I can't find the number you are searching for - searchfor: 2026540492 Â
Line 42: echo "I can't find the number you are searching for - searchfor: $searchfor"

 

I do not understand why there is a character after the number:

Line 32:  $searchfor = rtrim($confirmation_number);

 

How can I get rid of the character after the number, 2026540492 Â, and remove all spaces before and after the number?

 

 

<?php
 // Process valid_repair_upgradeform 
 error_reporting(-1);
 //Define Variable(s)
 $date = date("D  d M Y  - H:i:s ");
 $my_file = "s_vcs.txt";
 $my_path = $_SERVER['DOCUMENT_ROOT']."/home/users/web/b686/dom.horacela/public_html/";
 $my_name = "Newbieca";
 $my_mail = "[email protected]";
 $my_replyto = "[email protected]";
 $my_subject = "Order Validated";
 $my_message = "This order was validated Confirmation Number: $confirmation_number on Date: $date.\r\n\r\n";
 if (is_writable($my_file)) {
    echo " ";
 } else {
    echo 'The file is not writable\n\n';
 }
 if (is_readable($my_file)) {
    echo " ";
 } else {
    echo 'The file is not readable';
 }
 //Get Data From Form
 $confirmation_number = $_POST['confirmation_number'];
 // validate expected data exists 
 if(!isset($_POST['confirmation_number'])) {
  echo "No Confirmation_number.\n";
  die();
 }
 // Search file for Confirmation_number. If found call function 
 $MyFile = "s_vcs.txt";
 $searchfor = rtrim($confirmation_number);
 $fh = fopen(MyfFile, "r");
 $olddata = fread($fh, filesize($MyFile));
 if(strpos($olddata, $searchfor)) {
  echo "fount it";
  // Call Functions
  mail_attachment($my_file, $my_path, "[email protected]", $my_mail, $my_name, $my_replyto, $my_subject, $my_message);
 }
 else {
  echo "I can't find the number you are searching for - confirmation_number: $confirmation_number";
  echo "<br>";
  echo "I can't find the number you are searching for - searchfor: $searchfor\n\n";
 }
 fclose($fh);
 //FUNCTION(S) 
 function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
  $file = $path.$filename;
  $file_size = filesize($file);
  $handle = fopen($file,"r");
  $content = fread($handle,$file_size);
  fclose($handle);
  $content = chunk_split(base64_encode($content));
  $uid = md5(uniqid(time()));
  $name = basename($file);
  $header = "From: ".$from_name." <".$from_mail.">\r\n";
  $header .= "Reply-To: ".$replyto."\r\n";
  $header .= "MIME-Version: 1.0\r\n";
  $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
  $header .= "This is a multi-part message in MIME format.\r\n";
  $header .= "--".$uid."\r\n";
  $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
  $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
  $header .= $message."\r\n\r\n";
  $header .= "--".$uid."\r\n";
  $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
  $header .= "Content-Transfer-Encoding: base64\r\n";
  $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
  $header .= $content."\r\n\r\n";
  $header .= "--".$uid."--";
  if (mail($mailto, $subject, "", $header)) {
      echo "mail send ... OK"; // or use booleans here
  } else {
      echo "mail send ... ERROR!";
  }
 }
?>
 

Quote

post #4 in this thread has nothing to do with your problem. it's probably just a spammer testing if the account he created works

 

I agree

It has nothing to do with my problem.

 

 

What happened to post #4?

Quote

#4 Newbie
Hi. Maybe you can try utting the xml tag in the first line of your file.

 

I took the post away seeing as it did have nothing to do with anything.  What strikes me as more odd than post #4's existence is the fact that you felt the need to quote it as if to reminisce its irrelevance??

I took the post away seeing as it did have nothing to do with anything.  What strikes me as more odd than post #4's existence is the fact that you felt the need to quote it as if to reminisce its irrelevance??

 

We only knew post #4 for a short time, however I think his impact will be felt for years to come.  Looking back on the life of post #4, who can forget all of the humorous anecdotes and witty remarks, such as:

 

Hi. Maybe you can try utting the xml tag in the first line of your file.

 

Or the many insightful and informative contributions, such as:

 

Hi. Maybe you can try utting the xml tag in the first line of your file.

 

I'm sure that I'm not alone in my heartfelt reminiscing of the life of post #4.  Let us not forget the slogan that he lived by every day of his short life:

 

Hi. Maybe you can try utting the xml tag in the first line of your file.

 

RIP post #4.

your latest posted code is still missing the $ in front of the MyFile variable name and is therefor not reading the file at all. you would be getting several php error messages. you need to set php's error_reporting to E_ALL and display_errors to ON to get php to help you.

 

as to the extra characters on the end of the $confirmation_number value, where or how are the POST values being generated and submitted?

PaulRayan:  I fixed line 33:  $fh = fopen($MyfFile, "r");

                    Thank you!

mac_gyver: (1) I fixed line 33:  $fh = fopen($MyfFile, "r");

                   (2) Line 24: $confirmation_number = $_POST['confirmation_number'];

                        Line 31: $MyFile = "s_vcs.txt";

                        Line 32: $searchfor = trim($confirmation_number);
                        Line 33: $fh = fopen($MyfFile, "r");
                        Line 34: $olddata = fread($fh, filesize($MyFile));
                        Line 35: if(strpos($olddata, trim($searchfor))) {
                        Line 36:  echo "fount it";
                        Line 37: // Call Functions
                        Line 38:  mail_attachment($my_file, $my_path, "[email protected]", $my_mail, $my_name, $my_replyto, $my_subject, $my_message);
                        Line 39: }40: 
                        Line 40: else {
                        Line 41:  echo "I can't find the number you are searching for - $searchfor\n\n"; 
                        Line 42:  }
Note: Line 35 (above) produced this error: PHP Parse error:  syntax error, unexpected T_STRING in on line 35 

So, I removed the tirm() from line 35 after I posted the CODE:  if(strpos($olddata, $searchfor)) {

 

Now, I am getting line 41: I can't find the number you are searching for - 2026540492 Â

 

 

<?php
 // Process valid_repair_upgradeform 
 error_reporting(-1);
 //Define Variable(s)
 $date = date("D  d M Y - H:i:s ");
 $my_file = "s_vcs.txt";
 $my_path = $_SERVER['DOCUMENT_ROOT']."/home/users/web/b686/dom.horacela/public_html/";
 $my_name = "Newbieca";
 $my_mail = "[email protected]";
 $my_replyto = "[email protected]";
 $my_subject = "Order Validated";
 $my_message = "This order was validated Confirmation Number: $confirmation_number on Date: $date.\r\n\r\n";
 if (is_writable($my_file)) {
    echo " ";
 } else {
    echo 'The file is not writable\n\n';
 }
 if (is_readable($my_file)) {
    echo " ";
 } else {
    echo 'The file is not readable';
 }
 //Get Data From Form
 $confirmation_number = $_POST['confirmation_number'];
 // validate expected data exists 
 if(!isset($_POST['confirmation_number'])) {
  echo "No Confirmation_number.\n";
  die();
 }
 // Search file for Confirmation_number. If found call function 
 $MyFile = "s_vcs.txt";
 $searchfor = trim($confirmation_number);
 $fh = fopen($MyfFile, "r");
 $olddata = fread($fh, filesize($MyFile));
 if(strpos($olddata, trim($searchfor))) {
  echo "fount it";
  // Call Functions
  mail_attachment($my_file, $my_path, "[email protected]", $my_mail, $my_name, $my_replyto, $my_subject, $my_message);
 }
 else {
  echo "I can't find the number you are searching for - $searchfor\n\n";
 }
 fclose($fh);
 //FUNCTION(S) 
 function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
  $file = $path.$filename;
  $file_size = filesize($file);
  $handle = fopen($file,"r");
  $content = fread($handle,$file_size);
  fclose($handle);
  $content = chunk_split(base64_encode($content));
  $uid = md5(uniqid(time()));
  $name = basename($file);
  $header = "From: ".$from_name." <".$from_mail.">\r\n";
  $header .= "Reply-To: ".$replyto."\r\n";
  $header .= "MIME-Version: 1.0\r\n";
  $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
  $header .= "This is a multi-part message in MIME format.\r\n";
  $header .= "--".$uid."\r\n";
  $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
  $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
  $header .= $message."\r\n\r\n";
  $header .= "--".$uid."\r\n";
  $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
  $header .= "Content-Transfer-Encoding: base64\r\n";
  $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
  $header .= $content."\r\n\r\n";
  $header .= "--".$uid."--";
  if (mail($mailto, $subject, "", $header)) {
      echo "mail send ... OK"; // or use booleans here
  } else {
      echo "mail send ... ERROR!";
  }
 }
?>
 

PaulRyan: I replaced line 46: $searchfor = $confirmation_number;

                                              $searchfor = preg_replace('#[\D]#', '', $confirmation_number);

 

I'm still receiving Line 62: I can't find the number you are searching for - 2026540492 Â

                                        echo "I can't find the number you are searching for - $searchfor\n\n";

 

I have made several changes to the code:

 

 

<?php
 // Process valid_repair_upgradeform 
 error_reporting(-1);
 //Define Variable(s)
 $date = date("D  d M Y - H:i:s ");
 $my_file = "s_vcs.txt";
 $my_path = $_SERVER['DOCUMENT_ROOT']."/home/users/web/b686/dom.horacela/public_html/";
 $my_name = "Newbieca";
 $my_mail = "[email protected]";
 $my_replyto = "[email protected]";
 $my_subject = "Order Validated";
 $my_message = "This order was validated Confirmation Number: $confirmation_number on Date: $date.\r\n\r\n";
 if (is_writable($my_file)) {
    echo " ";
 } else {
    echo 'The file is not writable\n\n';
 }
 if (is_readable($my_file)) {
    echo " ";
 } else {
    echo 'The file is not readable';
 }
 //Get Data From Form
 $confirmation_number = $_POST['confirmation_number'];
 $Email = $_POST['Email'];
 $List = array();
 // validate expected data exists 
 if(!isset($_POST['confirmation_number'])) {
  echo "No Confirmation_number.\n";
  die();
 }
 if(!isset($_POST['Email'])) {
  echo "No Email address.\n";
  die();
 }
 //validate email address
 if (check_email_address($Email)) { 
  echo " ";
 } 
 else { 
  echo $Email . " is not a valid email address.\n";
  die();  
 }
 // Search file for Confirmation_number. If found call function 
 $MyFile = "s_vcs.txt";
 $searchfor = preg_replace('#[\D]#', '', $confirmation_number);
 $fh = fopen($MyFile, "r");
 if (is_readable($MyFile)) {
  echo " ";
 }
 else {
  echo 'The file is not readable';
 }
 $olddata = fread($fh, filesize($MyFile));
 if(strpos($olddata, $searchfor)) {
  echo "fount it";
  // Call Functions
  mail_attachment($my_file, $my_path, "[email protected]", $my_mail, $my_name, $my_replyto, $my_subject, $my_message);
  email();
 }
 else {
 
 }
 fclose($fh);
 //FUNCTION(S) 
 function check_email_address($Email) { 
  // First, we check that there's one @ symbol, and that the lengths are right 
  if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $Email)) { 
   // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
   echo "Email invalid because wrong number of characters in one section, or wrong number of @ symbols.\n"; 
   echo "<br />\n";
   return false; 
  } 
  // Split it into sections to make life easier
  $Email_array = explode("@", $Email); $local_array = explode(".", $Email_array[0]); 
  for ($i = 0; $i < sizeof($local_array); $i++) { 
   if  (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",$local_array[$i])) { 
    echo "Split it into sections to make life easier\n";
    echo "<br />\n";
    return false; 
   } 
  } 
  if (!ereg("^\[?[0-9\.]+\]?$",$Email_array[1])) { 
   // Check if domain is IP. If not, it should be valid domain name 
   //echo "Check if domain is IP. If not, it should be valid domain name\n"; 
   //echo "<br />\n"; 
   $domain_array = explode(".", $Email_array[1]); 
   if(sizeof($domain_array) < 2) { 
return false; 
// Not enough parts to domain 
    echo "Not enough parts to domain\n"; 
    echo "<br />\n"; 
   } 
   for ($i = 0; $i < sizeof($domain_array); $i++) { 
if(!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { 
return false; 
} 
   } 
   } 
   return true; 
 }
 function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
  // Email phpnewbieca with attachment
  global $date, $my_file, $my_path, $my_name, $my_mail, $my_replyto, $my_subject, $my_message, $confirmation_number, $Email, $List, $MyFile, $searchfor,
  $fh, $olddata;
  // 
  $file = $path.$filename;
  $file_size = filesize($file);
  $handle = fopen($file,"r");
  $content = fread($handle,$file_size);
  fclose($handle);
  $content = chunk_split(base64_encode($content));
  $uid = md5(uniqid(time()));
  $name = basename($file);
  $header = "From: ".$from_name." <".$from_mail.">\r\n";
  $header .= "Reply-To: ".$replyto."\r\n";
  $header .= "MIME-Version: 1.0\r\n";
  $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
  $header .= "This is a multi-part message in MIME format.\r\n";
  $header .= "--".$uid."\r\n";
  $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
  $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
  $header .= $message."\r\n\r\n";
  $header .= "--".$uid."\r\n";
  $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
  $header .= "Content-Transfer-Encoding: base64\r\n";
  $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
  $header .= $content."\r\n\r\n";
  $header .= "--".$uid."--";
  if (mail($mailto, $subject, "", $header)) {
      echo "mail send ... OK"; // or use booleans here
  } else {
      echo "mail send ... ERROR!";
  }
 }
 function email() {
  // Email Customer HTML
  global $date, $my_file, $my_path, $my_name, $my_mail, $my_replyto, $my_subject, $my_message, $confirmation_number, $Email, $List, $MyFile, $searchfor,
  $fh, $olddata;
  //Stuff  Array
  if(isset($_POST['confirmation_number'])) {  
  $List[0]="$confirmation_number<br><br>";
  }
  else {
  $List[0]=" ";
  }
  if(isset($_POST['Email'])) {   
   $List[1]="$Email<br>";
  }
  else {
  $List[1]=" ";
  }
  $to  = "$Email";
  $subject = "RE: Validation of Repair/Upgrade Order\n\n";
  //begin of HTML message
  $message = <<<EOF
  <html>
    <body BGCOLOR='tan' TEXT='black'><br>
    <br>
<Font size="1+"><b>Thank you for validating your order $date.</font></b><br> 
    CONFIRMATION NUMBER: $List[0]
    <Font size="1+">Please visit us again <a href="http://www.horacefranklinjr.com/"> Horace's Home Computer Repair<Font></a>
   </body>
  </html>
EOF;
  //end of message
  $headers  = "Mime-Version: 1.0" . "\r\n";
  $headers .= "Content-type: text/html; charset=iso-8859-1" ."\r\n";
  $headers .= "Sensitivity: Personal" . "\r\n";  
  $headers .= "From: $From" . "\r\n";
  $headers .= "Reply To: $From" . "\r\n";
  $headers .= "Return-Path: $From" . "\r\n"; 
  $headers .= "X-Priority: 1 (Highest)" . "\r\n";
  $headers .= "X-MSMail-Priority: High" . "\r\n";
  $headers .= "Importance: High" . "\r\n";
  // now lets send the email.
  mail($to, $subject, $message, $headers);
   echo " ";
 }
 ?>

I cannot edit my last post, take a look at this.

 

I have changed around some of the logic, as I was getting a lot of errors when I ran the code on my dev setup.

 

I have replace ereg with preg_match.

I have used ternary operators for some of the assignment of variables.

I have removed unneeded variables best I can.

Instead of echo-ing from the function, I have chosen the return any error information.

<?PHP

  //### Process valid_repair_upgradeform
  error_reporting(-1);
 
  //### Get Data From Form
  $confirmation_number = isset($_POST['confirmation_number']) ? $_POST['confirmation_number'] : FALSE ;
  $Email = isset($_POST['Email']) ? $_POST['Email'] : FALSE ;
 
  $List = array();
 
  //### Validate confirmation number
  if(empty($confirmation_number)) {
    echo 'No confirmation number.'. PHP_EOL;
    exit;
  } else {
    //### Remove anything that is a not a number
    $confirmation_number = preg_replace('#[\D]#', '', $confirmation_number);
  }
 
  //### Validate e-mail address
  if(empty($Email)) {
    echo 'No e-mail address.'. PHP_EOL;
    exit;
  } else if(($emailError = check_email_address($Email)) !== true) {
    echo $emailError;
    exit;
  }
 
  //Define Variable(s)
  $date = date("D  d M Y - H:i:s ");
  $my_file = "s_vcs.txt";
  $my_path = $_SERVER['DOCUMENT_ROOT']."/home/users/web/b686/dom.horacela/public_html/";
  $my_name = "Newbieca";
  $my_mail = "[email protected]";
  $my_replyto = "[email protected]";
  $my_subject = "Order Validated";
  $my_message = "This order was validated Confirmation Number: $confirmation_number on Date: $date.\r\n\r\n";
 
  //### Check if file is writable
  if(!is_writable($my_file)) {
    echo 'The file is not writable.'. PHP_EOL;
    exit;
  }

  //### Search file for Confirmation_number. If found call function
  $searchfor = preg_replace('#[\D]#', '', $confirmation_number);
 
  //### Check if file is readable
  if (!is_readable($my_file)) {
    echo 'The file is not readable'. PHP_EOL;
    exit;
  } else {
    //### Open the file for reading
    $fh = fopen($my_file, "r+");
    $olddata = fread($fh, filesize($my_file));
    
    //### Search a match
    if(strpos($olddata, $searchfor) != FALSE) {
      echo 'Found it!';
      
      echo mail_attachment($my_file, $my_path, "[email protected]", $my_mail, $my_name, $my_replyto, $my_subject, $my_message);
      echo email();
    }
    
    fclose($fh);
  }
 
  //FUNCTION(S)
  function check_email_address($Email) {
    // First, we check that there's one @ symbol, and that the lengths are right
    if (!preg_match("/^[^@]{1,64}@[^@]{1,255}$/", $Email)) {
      // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
      return "Email invalid because wrong number of characters in one section, or wrong number of @ symbols.\n";
    }
 
    // Split it into sections to make life easier
    $Email_array = explode("@", $Email); $local_array = explode(".", $Email_array[0]);
    for ($i = 0; $i < sizeof($local_array); $i++) {
      if(!preg_match("/^(([A-Za-z0-9!#$%&'*+\/=?^_`{|}~-][A-Za-z0-9!#$%&'*+\/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$/",$local_array[$i])) {
        return "Split it into sections to make life easier\n";
      }
    }
 
    if (!preg_match("/^\[?[0-9\.]+\]?$/",$Email_array[1])) {
     // Check if domain is IP. If not, it should be valid domain name
     //echo "Check if domain is IP. If not, it should be valid domain name\n";
     //echo "<br />\n";
     $domain_array = explode(".", $Email_array[1]);
     if(sizeof($domain_array) < 2) {
       return "Not enough parts to domain\n";
     }
   
     for ($i = 0; $i < sizeof($domain_array); $i++) {
       if(!preg_match("/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$/", $domain_array[$i])) {
         return false;
       }
     }
   }
   return true;
 }// End of email check function
 
 function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
   // Email phpnewbieca with attachment
   global $date, $my_file, $my_path, $my_name, $my_mail, $my_replyto, $my_subject, $my_message, $confirmation_number, $Email, $List, $my_file, $searchfor,
   $fh, $olddata;
   //
   $file = $path.$filename;
   $file_size = filesize($file);
   $handle = fopen($file,"r");
   $content = fread($handle,$file_size);
   fclose($handle);
   $content = chunk_split(base64_encode($content));
   $uid = md5(uniqid(time()));
   $name = basename($file);
   $header = "From: ".$from_name." <".$from_mail.">\r\n";
   $header .= "Reply-To: ".$replyto."\r\n";
   $header .= "MIME-Version: 1.0\r\n";
   $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
   $header .= "This is a multi-part message in MIME format.\r\n";
   $header .= "--".$uid."\r\n";
   $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
   $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
   $header .= $message."\r\n\r\n";
   $header .= "--".$uid."\r\n";
   $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
   $header .= "Content-Transfer-Encoding: base64\r\n";
   $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
   $header .= $content."\r\n\r\n";
   $header .= "--".$uid."--";
   
   if(mail($mailto, $subject, "", $header)) {
     return "mail attachment send ... OK <br>"; // or use booleans here
   } else {
     return "mail attachment send ... ERROR!<br>";
   }
 }//~End of mail attachment function
 
  function email() {
    // Email Customer HTML
    global $date, $my_file, $my_path, $my_name, $my_mail, $my_replyto, $my_subject, $my_message, $confirmation_number, $Email, $List, $my_file, $searchfor,
    $fh, $olddata;
 
    //Stuff  Array
    $List[0] = isset($_POST['confirmation_number']) ? $confirmation_number.' <br><br>' : '' ;
    
    $List[1] = isset($_POST['Email']) ? $Email.'<br>' : '' ;
 
    $to  = "$Email";
    $subject = "RE: Validation of Repair/Upgrade Order\n\n";
    //begin of HTML message
    $message = <<<EOF
  <html>
    <body BGCOLOR='tan' TEXT='black'><br>
    <br>
<Font size="1+"><b>Thank you for validating your order $date.</font></b><br>
    CONFIRMATION NUMBER: $List[0]
    <Font size="1+">Please visit us again <a href="http://www.horacefranklinjr.com/"> Horace's Home Computer Repair<Font></a>
   </body>
  </html>
EOF;

    //end of message
    $headers  = "Mime-Version: 1.0" . "\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1" ."\r\n";
    $headers .= "Sensitivity: Personal" . "\r\n";  
    $headers .= "From: $From" . "\r\n";
    $headers .= "Reply To: $From" . "\r\n";
    $headers .= "Return-Path: $From" . "\r\n";
    $headers .= "X-Priority: 1 (Highest)" . "\r\n";
    $headers .= "X-MSMail-Priority: High" . "\r\n";
    $headers .= "Importance: High" . "\r\n";
    
    // now lets send the email.
    if(mail($to, $subject, $message, $headers)) {
      return "mail send ... OK <br>"; // or use booleans here
    } else {
      return "mail send ... ERROR! <br>";
    }
  }
 ?>

 

I cannot edit my last post, take a look at this.

 

I have changed around some of the logic, as I was getting a lot of errors when I ran the code on my dev setup.

 

I have replace ereg with preg_match.

I have used ternary operators for some of the assignment of variables.

I have removed unneeded variables best I can.

Instead of echo-ing from the function, I have chosen the return any error information.

<?PHP

  //### Process valid_repair_upgradeform
  error_reporting(-1);
 
  //### Get Data From Form
  $confirmation_number = isset($_POST['confirmation_number']) ? $_POST['confirmation_number'] : FALSE ;
  $Email = isset($_POST['Email']) ? $_POST['Email'] : FALSE ;
 
  $List = array();
 
  //### Validate confirmation number
  if(empty($confirmation_number)) {
    echo 'No confirmation number.'. PHP_EOL;
    exit;
  } else {
    //### Remove anything that is a not a number
    $confirmation_number = preg_replace('#[\D]#', '', $confirmation_number);
  }
 
  //### Validate e-mail address
  if(empty($Email)) {
    echo 'No e-mail address.'. PHP_EOL;
    exit;
  } else if(($emailError = check_email_address($Email)) !== true) {
    echo $emailError;
    exit;
  }
 
  //Define Variable(s)
  $date = date("D  d M Y - H:i:s ");
  $my_file = "s_vcs.txt";
  $my_path = $_SERVER['DOCUMENT_ROOT']."/home/users/web/b686/dom.horacela/public_html/";
  $my_name = "Newbieca";
  $my_mail = "[email protected]";
  $my_replyto = "[email protected]";
  $my_subject = "Order Validated";
  $my_message = "This order was validated Confirmation Number: $confirmation_number on Date: $date.\r\n\r\n";
 
  //### Check if file is writable
  if(!is_writable($my_file)) {
    echo 'The file is not writable.'. PHP_EOL;
    exit;
  }

  //### Search file for Confirmation_number. If found call function
  $searchfor = preg_replace('#[\D]#', '', $confirmation_number);
 
  //### Check if file is readable
  if (!is_readable($my_file)) {
    echo 'The file is not readable'. PHP_EOL;
    exit;
  } else {
    //### Open the file for reading
    $fh = fopen($my_file, "r+");
    $olddata = fread($fh, filesize($my_file));
    
    //### Search a match
    if(strpos($olddata, $searchfor) != FALSE) {
      echo 'Found it!';
      
      echo mail_attachment($my_file, $my_path, "[email protected]", $my_mail, $my_name, $my_replyto, $my_subject, $my_message);
      echo email();
    }
    
    fclose($fh);
  }
 
  //FUNCTION(S)
  function check_email_address($Email) {
    // First, we check that there's one @ symbol, and that the lengths are right
    if (!preg_match("/^[^@]{1,64}@[^@]{1,255}$/", $Email)) {
      // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
      return "Email invalid because wrong number of characters in one section, or wrong number of @ symbols.\n";
    }
 
    // Split it into sections to make life easier
    $Email_array = explode("@", $Email); $local_array = explode(".", $Email_array[0]);
    for ($i = 0; $i < sizeof($local_array); $i++) {
      if(!preg_match("/^(([A-Za-z0-9!#$%&'*+\/=?^_`{|}~-][A-Za-z0-9!#$%&'*+\/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$/",$local_array[$i])) {
        return "Split it into sections to make life easier\n";
      }
    }
 
    if (!preg_match("/^\[?[0-9\.]+\]?$/",$Email_array[1])) {
     // Check if domain is IP. If not, it should be valid domain name
     //echo "Check if domain is IP. If not, it should be valid domain name\n";
     //echo "<br />\n";
     $domain_array = explode(".", $Email_array[1]);
     if(sizeof($domain_array) < 2) {
       return "Not enough parts to domain\n";
     }
   
     for ($i = 0; $i < sizeof($domain_array); $i++) {
       if(!preg_match("/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$/", $domain_array[$i])) {
         return false;
       }
     }
   }
   return true;
 }// End of email check function
 
 function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
   // Email phpnewbieca with attachment
   global $date, $my_file, $my_path, $my_name, $my_mail, $my_replyto, $my_subject, $my_message, $confirmation_number, $Email, $List, $my_file, $searchfor,
   $fh, $olddata;
   //
   $file = $path.$filename;
   $file_size = filesize($file);
   $handle = fopen($file,"r");
   $content = fread($handle,$file_size);
   fclose($handle);
   $content = chunk_split(base64_encode($content));
   $uid = md5(uniqid(time()));
   $name = basename($file);
   $header = "From: ".$from_name." <".$from_mail.">\r\n";
   $header .= "Reply-To: ".$replyto."\r\n";
   $header .= "MIME-Version: 1.0\r\n";
   $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
   $header .= "This is a multi-part message in MIME format.\r\n";
   $header .= "--".$uid."\r\n";
   $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
   $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
   $header .= $message."\r\n\r\n";
   $header .= "--".$uid."\r\n";
   $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
   $header .= "Content-Transfer-Encoding: base64\r\n";
   $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
   $header .= $content."\r\n\r\n";
   $header .= "--".$uid."--";
   
   if(mail($mailto, $subject, "", $header)) {
     return "mail attachment send ... OK <br>"; // or use booleans here
   } else {
     return "mail attachment send ... ERROR!<br>";
   }
 }//~End of mail attachment function
 
  function email() {
    // Email Customer HTML
    global $date, $my_file, $my_path, $my_name, $my_mail, $my_replyto, $my_subject, $my_message, $confirmation_number, $Email, $List, $my_file, $searchfor,
    $fh, $olddata;
 
    //Stuff  Array
    $List[0] = isset($_POST['confirmation_number']) ? $confirmation_number.' <br><br>' : '' ;
    
    $List[1] = isset($_POST['Email']) ? $Email.'<br>' : '' ;
 
    $to  = "$Email";
    $subject = "RE: Validation of Repair/Upgrade Order\n\n";
    //begin of HTML message
    $message = <<<EOF
  <html>
    <body BGCOLOR='tan' TEXT='black'><br>
    <br>
<Font size="1+"><b>Thank you for validating your order $date.</font></b><br>
    CONFIRMATION NUMBER: $List[0]
    <Font size="1+">Please visit us again <a href="http://www.horacefranklinjr.com/"> Horace's Home Computer Repair<Font></a>
   </body>
  </html>
EOF;

    //end of message
    $headers  = "Mime-Version: 1.0" . "\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1" ."\r\n";
    $headers .= "Sensitivity: Personal" . "\r\n";  
    $headers .= "From: $From" . "\r\n";
    $headers .= "Reply To: $From" . "\r\n";
    $headers .= "Return-Path: $From" . "\r\n";
    $headers .= "X-Priority: 1 (Highest)" . "\r\n";
    $headers .= "X-MSMail-Priority: High" . "\r\n";
    $headers .= "Importance: High" . "\r\n";
    
    // now lets send the email.
    if(mail($to, $subject, $message, $headers)) {
      return "mail send ... OK <br>"; // or use booleans here
    } else {
      return "mail send ... ERROR! <br>";
    }
  }
 ?>

Who's da man Paul's da man.

Thanks for all your help.

Now i'll spend the next two weeks looking up the new code you used that's waaaaaaay above my level. :happy-04:  :happy-04:  :happy-04:

 

I;ll run a few more test ND MARK THIS SOLVED. :o  :o  :o

 

 

<?PHP
 
  //### Process valid_repair_upgradeform
  error_reporting(-1);
 
  //### Get Data From Form
  $confirmation_number = isset($_POST['confirmation_number']) ? $_POST['confirmation_number'] : FALSE ;
  $Email = isset($_POST['Email']) ? $_POST['Email'] : FALSE ;
 
  $List = array();
 
  //### Validate confirmation number
  if(empty($confirmation_number)) {
    echo 'No confirmation number.'. PHP_EOL;
    exit;
  } else {
    //### Remove anything that is a not a number
    $confirmation_number = preg_replace('#[\D]#', '', $confirmation_number);
  }
 
  //### Validate e-mail address
  if(empty($Email)) {
    echo 'No e-mail address.'. PHP_EOL;
    exit;
  } else if(($emailError = check_email_address($Email)) !== true) {
    echo $emailError;
    exit;
  }
 
  //Define Variable(s)
  $date = date("D  d M Y - H:i:s ");
  $filename = "s_vcs.txt";
  $path = $_SERVER['DOCUMENT_ROOT']."/home/users/web/b686/dom.horacela/public_html/";
  $mailto = "$Email";
  $name = "phpnewbieca"
  $mail = "[email protected]";
  $replyto = "[email protected]";
  $subject = "Order Validated";
  $message = "This order was validated: \r\n Confirmation Number: $confirmation_number \r\n Date: $date.\r\n\r\n";
 
  //### Check if file is writable
  if(!is_writable($filename)) {
    echo 'The file is not writable.'. PHP_EOL;
    exit;
  }
 
  //### Search file for Confirmation_number. If found call function
  $searchfor = preg_replace('#[\D]#', '', $confirmation_number);
 
  //### Check if file is readable
  if (!is_readable($filename)) {
    echo 'The file is not readable'. PHP_EOL;
    exit;
  } else {
    //### Open the file for reading
    $fh = fopen($filename, "r+");
    $olddata = fread($fh, filesize($filename));
    
    //### Search a match
    if(strpos($olddata, $searchfor) != FALSE) {
      // call functions
      valid_repair_upgrade_1($filename, $path, $mailto, $name, $mail, $replyto, $subject, $message);
      valid_repair_upgrade_2();
 valid_repair_upgrade_3();
    }
else {
 echo " I can't find the number you entered: $confirmation_number";
    }
    fclose($fh);
  }
 
  //FUNCTION(S)
  function check_email_address($Email) {
    // First, we check that there's one @ symbol, and that the lengths are right
    if (!preg_match("/^[^@]{1,64}@[^@]{1,255}$/", $Email)) {
      // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
      return "Email invalid because wrong number of characters in one section, or wrong number of @ symbols.\n";
    }
 
    // Split it into sections to make life easier
    $Email_array = explode("@", $Email); $local_array = explode(".", $Email_array[0]);
    for ($i = 0; $i < sizeof($local_array); $i++) {
      if(!preg_match("/^(([A-Za-z0-9!#$%&'*+\/=?^_`{|}~-][A-Za-z0-9!#$%&'*+\/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$/",$local_array[$i])) {
        return "Split it into sections to make life easier\n";
      }
    }
 
    if (!preg_match("/^\[?[0-9\.]+\]?$/",$Email_array[1])) {
     // Check if domain is IP. If not, it should be valid domain name
     //echo "Check if domain is IP. If not, it should be valid domain name\n";
     //echo "<br />\n";
     $domain_array = explode(".", $Email_array[1]);
     if(sizeof($domain_array) < 2) {
       return "Not enough parts to domain\n";
     }
   
     for ($i = 0; $i < sizeof($domain_array); $i++) {
       if(!preg_match("/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$/", $domain_array[$i])) {
         return false;
       }
     }
   }
   return true;
 }// End of email check function
 
 function valid_repair_upgrade_1($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
   // Email Horace with attachment
   global $date, $filename, $path, $mailto, $name, $mail, $replyto, $subject, $message, $confirmation_number, $Email, $List, $MyFile,
   $searchfor, $fh, $olddata;
   //
   $file = $path.$filename;
   $file_size = filesize($filename);
   $handle = fopen($filename,"r");
   $content = fread($handle,$file_size);
   fclose($handle);
   $content = chunk_split(base64_encode($content));
   $uid = md5(uniqid(time()));
   $name = basename($file);
   $header = "From: ".$name." <".$mail.">\r\n";
   $header .= "Reply-To: ".$replyto."\r\n";
   $header .= "MIME-Version: 1.0\r\n";
   $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
   $header .= "This is a multi-part message in MIME format.\r\n";
   $header .= "--".$uid."\r\n";
   $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
   $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
   $header .= $message."\r\n\r\n";
   $header .= "--".$uid."\r\n";
   $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
   $header .= "Content-Transfer-Encoding: base64\r\n";
   $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
   $header .= $content."\r\n\r\n";
   $header .= "--".$uid."--";
   
   if(mail($mailto, $subject, "", $header)) {
     return "mail attachment send ... OK <br>"; // or use booleans here
   } else {
     return "mail attachment send ... ERROR!<br>";
   }
 }//~End of mail attachment function
 
  function valid_repair_upgrade_2() {
    // Email Customer HTML
    global $date, $filename, $path, $mailto, $name, $mail, $replyto, $subject, $message, $confirmation_number, $Email, $List, $MyFile,
    $searchfor, $fh, $olddata;
    //
$to  = "$Email";
    $subject = "Order Validated\n\n";
    //begin of HTML message
    $message = <<<EOF
  <html>
    <body BGCOLOR='tan' TEXT='black'><br>
    <br>
    <b>Thank you for validating your order:</b><br>
Date: $date.<br>
    CONFIRMATION NUMBER: $confirmation_number<br><br>
    Please visit us again <a href="http://www.horacefranklinjr.com/"> Horace's Home Computer Repair</a><br>
   </body>
  </html>
EOF;
    //end of message
    $headers  = "Mime-Version: 1.0" . "\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1" ."\r\n";
    $headers .= "Sensitivity: Personal" . "\r\n";  
    $headers .= "From: $mail" . "\r\n";
    $headers .= "Reply To: $mail" . "\r\n";
    $headers .= "Return-Path: $mail" . "\r\n";
    $headers .= "X-Priority: 1 (Highest)" . "\r\n";
    $headers .= "X-MSMail-Priority: High" . "\r\n";
    $headers .= "Importance: High" . "\r\n";
    // now lets send the email.
    mail($to, $subject, $message, $headers);
  }
  function valid_repair_upgrade_3() {
  // Print to browser
  global $date, $filename, $path, $mailto, $name, $mail, $replyto, $subject, $message, $confirmation_number, $Email, $List, $MyFile,
  $searchfor, $fh, $olddata;
  // 
  echo " <html>\n";
  echo " <head>\n";
  echo " <title>valid Repair/Upgrade</title>\n";
  echo " </head>\n";
  echo " <body BGCOLOR='tan' TEXT='black'>\n"; 
  echo " <br /><br /><br /><br />\n";   
  echo " <table width='700' Align='center'>\n";
  echo " <tr>\n";
  echo " <td width='700' Align='center'>\n";
  echo " <font size='+2'><b>Thank you for validating your order $date.</font></b>\n";
  echo " <br /><br />\n";  
  echo " <font size='+1'>CONFIRMATION NUMBER: $confirmation_number]</font>\n";
  echo " <br /><br />\n";   
  echo " <font size='+2'>Please visit us again <a href=\"http://www.horacefranklinjr.com\"> Horace's Home Computer Repair</a></font>\n";
  echo " <br />\n"; 
  echo " </td>\n";  
  echo " </tr>\n"; 
  echo " </table>\n";
  echo " </body>\n";
  echo " </html>\n";
 }  
 ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.