phpnewbieca Posted November 14, 2009 Share Posted November 14, 2009 I am trying to send the contents of an array $lines_array via email. I receive the following error message: Parse error: syntax error, unexpected '=' in /home/xgasq39z/public_html/valid_contact.php on line 29 I cannot find an error on line 29. So, I am assuming the error is on line 30. I cannot determine what I am doing wrong. Help, Please! <?php $Date = date("D d M Y - H:i:s "); $confirmation_number = $_POST['confirmation_number']; $from = "[email protected]"; // validation expected data exists if(!isset($_POST['confirmation_number'])) { died('We are sorry, but there appears to be a problem with the form your submitted.'); } // Call Function Send_Contact(); //FUNCTION function Send_Contact() { global $Date, $confirmation_number, $from; $MyFile = "data.txt"; $fh = fopen($MyFile,"r"); rewind($fh); if(!$fh) { die("couldn't open file <i>$MyFile</i>"); } else { while(!feof($MyFile)) { $lines_array = file($MyFile); } fclose($fh); if(in_array("Confirmation Number: $confirmation_number",$lines_array,true)){ $subject = " Valid - Contact Us"; $email_message = " Contact Information has been validated.\n"; $email_message.= " Contact requestor within 48 hours.\n"; [b]*** 29 [/b] $email_message.= " Confirmation Number: $confirmation_number\n"; [b]*** 30 [/b] $email_message.= " $lines_array"; // create email headers $headers = 'From: '.$from."\r\n". 'Reply-To: '.$from."\r\n" . 'X-Mailer: PHP/' . phpversion(); $formsent = mail($from, $subject, $email_message, $headers); if ($formsent) { echo $formsent; } else { echo " "email was not sent. The CONFIRMATION NUMBER you enter is not in or records."; die; } } } ?> [/Code] Link to comment https://forums.phpfreaks.com/topic/181542-send-contents-of-array-via-email/ Share on other sites More sharing options...
rarebit Posted November 14, 2009 Share Posted November 14, 2009 It's happening because the data is an array, not a string! You need to iterate through it, something like this maybe... foreach($email_message as $e) { $email_message .= $e."\n"; } Link to comment https://forums.phpfreaks.com/topic/181542-send-contents-of-array-via-email/#findComment-957604 Share on other sites More sharing options...
phpnewbieca Posted November 19, 2009 Author Share Posted November 19, 2009 Where would I put this code (I am a newbie to php)? Will this line of code load the file as a string? $lines = file(myfile.txt); If yes Would it print the contents of the string by using this line of code? $email_message.= " $lines"; Link to comment https://forums.phpfreaks.com/topic/181542-send-contents-of-array-via-email/#findComment-960998 Share on other sites More sharing options...
megaresp Posted November 19, 2009 Share Posted November 19, 2009 Where would I put this code (I am a newbie to php)? Just to clarify, in this line... > $email_message.= " $lines_array"; ...you are attempting to append the array $lines_array onto the string $email_message. I suggest you use the implode command to create a string from your array, and append that to your string. Link to comment https://forums.phpfreaks.com/topic/181542-send-contents-of-array-via-email/#findComment-961033 Share on other sites More sharing options...
phpnewbieca Posted November 21, 2009 Author Share Posted November 21, 2009 What if I do this: $file = file_get_content($MyFile); email_message.= "$file"; Link to comment https://forums.phpfreaks.com/topic/181542-send-contents-of-array-via-email/#findComment-962586 Share on other sites More sharing options...
waynew Posted November 21, 2009 Share Posted November 21, 2009 Instead of foreach($email_message as $e) { $email_message .= $e."\n"; } You're appending the array value to the actual array? <?php $message = implode("\n",$lines_array); ?> Link to comment https://forums.phpfreaks.com/topic/181542-send-contents-of-array-via-email/#findComment-962629 Share on other sites More sharing options...
waynew Posted November 21, 2009 Share Posted November 21, 2009 What if I do this: $file = file_get_content($MyFile); email_message.= "$file"; file_get_content() isn't a function (you're thinking about file_get_contents()) so you'd get a syntax error. Other than that, I can't see anything else wrong with what you're doing. Link to comment https://forums.phpfreaks.com/topic/181542-send-contents-of-array-via-email/#findComment-962631 Share on other sites More sharing options...
phpnewbieca Posted November 25, 2009 Author Share Posted November 25, 2009 The code below allows me to send the contents of a txt file via email using the mail() function :D <?php // Processess Forml $Date = date("D d M Y - H:i:s "); $confirmation_number = $_POST['confirmation_number']; $MyFile = "myfile.txt"; $from = "[email protected]"; // validation expected data exists if(!isset($_POST['confirmation_number'])) { died('We are sorry, but there appears to be a problem with the form your submitted.'); } // Call Function Appointment_1(); Appointment_2(); //FUNCTION function Appointment_1() { global $Date, $confirmation_number, $from, $MyFile; $fh = fopen($MyFile,"r"); rewind($fh); if(!$fh) { die("couldn't open file <i>$MyFile</i>"); } else { $file = file_get_contents("$MyFile"); } fclose($fh); if(strstr($file,$confirmation_number)) { $subject = "Valid - Appointment Request"; $email_message = "Appointment Request has been validated.\n"; $email_message.= "Contact requestor within 48 hours.\n"; $email_message.= "Confirmation Number: $confirmation_number\n"; $email_message.= " $file"; // create email headers $headers = 'From: '.$from."\r\n". 'Reply-To: '.$from."\r\n" . 'X-Mailer: PHP/' . phpversion(); $formsent = mail($from, $subject, $email_message, $headers); if ($formsent) { echo $formsent; } else { echo "email was not sent. The CONFIRMATION NUMBER you enter is not in or records."; die; } } } function Appointment_2() { $Send_to = '[email protected]'; $From = '[email protected]'; $Subject = 'Valid - Appointment Request'; //supply the text and html versions of your email message $text = ''; $html = ''; //provide path to the file to be attached $file = '/home/xgasq39z/public_html/appointment.txt'; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r',time())); //define the headers we want passed. Note that they are separated with \r\n $headers = "From: " ."<"."$From".">"."\n"; $headers.= "Reply-To: "."<"."$From".">"; //add boundary string and mime type specification $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-{$random_hash}\""; //read the atachment file contents into a string, //encode it with MIME base64, //and split it into smaller chunks $attachment = chunk_split(base64_encode(file_get_contents($file) )); //define the body of the message. $body = "--PHP-mixed-{$random_hash}\r\n" . "Content-Type: multipart/alternative; boundary=\"PHP-alt-{$random_hash}\"\r\n" . "--PHP-alt-{$random_hash}\r\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n" . "Content-Transfer-Encoding: 7bit\r\n\r\n" . "{$text}\r\n\r\n" . "--PHP-alt-{$random_hash}\r\n\r\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\r\n" . "Content-Transfer-Encoding: 7bit\r\n\r\n" . "{$html}\r\n\r\n" . "--PHP-alt-{$random_hash}--\r\n\r\n" . "--PHP-mixed-{$random_hash}\r\n" . "Content-Type: " . mime_content_type($file) . "; name=\"" . basename($file) . "\"\r\n" . "Content-Transfer-Encoding: base64\r\n" . "Content-Disposition: attachment\r\n\r\n" . "{$attachment}\r\n" . "--PHP-mixed-{$random_hash}--\r\n\r\n"; //send the email $mail_sent = @mail($Send_To, $Subject, $body, $headers ); echo " $mail_sent"; if ($mail_sent){ echo "Mail sent"; } } ?> Thank you! Link to comment https://forums.phpfreaks.com/topic/181542-send-contents-of-array-via-email/#findComment-965165 Share on other sites More sharing options...
phpnewbieca Posted November 25, 2009 Author Share Posted November 25, 2009 function Appointment_1() is the function that puts the content of $file in an email function Appointment_2() still has problems sending the file as an attachment Link to comment https://forums.phpfreaks.com/topic/181542-send-contents-of-array-via-email/#findComment-965175 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.