croix Posted October 19, 2007 Share Posted October 19, 2007 Hello, What I am currently working on is a web form that emails me the info submitted, along with an attached file, and writes the info to the database (minus the attachment, im not getting that deep yet) The code is a combination of a mail script I have been using for a while, and a tutorial I found online. Im having trouble combining the two. My first problem is probably something stupid, though im sure there will be more. Parse error: syntax error, unexpected T_STRING in /home/sliquidc/public_html/thenannygroup/apply.php on line 96 96 is the mail($to_email, $subject ....... line - and also part of the code from the tutorial. <?php function sendMail() { if (!isset ($_POST['agreement'])) { //Oops, you did not agree to our terms die ("<p>Oops! You did not agree to our Terms of Employment! Click on the back arrow to go back</p>"); } else { $from_name = stripslashes($_POST['from_name']); $from_email = stripslashes($_POST['from_email']); $to_email = stripslashes($_POST['to_email']); $firstname = stripslashes($_POST['firstname']); $lastname = stripslashes($_POST['lastname']); $phone = stripslashes($_POST['phone']); $fax = stripslashes($_POST['fax']); $address = stripslashes($_POST['address']); $address2 = stripslashes($_POST['address2']); $state = stripslashes($_POST['state']); $city = stripslashes($_POST['city']); $zip = stripslashes($_POST['zip']); $email = stripslashes($_POST['email']); $available = stripslashes($_POST['available']); $livein = stripslashes($_POST['livein']); $overnights = stripslashes($_POST['overnights']); $travel = stripslashes($_POST['travel']); $fulltime = stripslashes($_POST['fulltime']); $parttime = stripslashes($_POST['parttime']); $comment = stripslashes($_POST['comment']); $agreement = stripslashes($_POST['agreement']); $resume = $_FILES['resume']['tmp_name']; $resume_name = $_FILES['resume']['name']; if (is_uploaded_file($resume)) { //Do we have a file uploaded? $fp = fopen($resume, "rb"); //Open it $data = fread($fp, filesize($resume)); //Read it $data = chunk_split(base64_encode($data)); //Chunk it up and encode it as base64 so it can be emailed fclose($fp); } //Let's start our headers ini_set(SMTP, "mail.thenannygroup.com"); ini_set(smtp_port, 25); ini_set(sendmail_from, "web@thenannygroup.com"); $headers = "From: $from_name<" . $_POST['from_email'] . ">\n"; $headers .= "Reply-To: <" . $_POST['from_email'] . ">\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/related; type=\"multipart/alternative\"; boundary=\"----=MIME_BOUNDRY_main_message\"\n"; $headers .= "X-Sender: $from_name<" . $_POST['from_email'] . ">\n"; $headers .= "X-Mailer: PHP4\n"; $headers .= "X-Priority: 3\n"; //1 = Urgent, 3 = Normal $headers .= "Return-Path: <" . $_POST['from_email'] . ">\n"; $headers .= "This is a multi-part message in MIME format.\n"; $headers .= "------=MIME_BOUNDRY_main_message \n"; $headers .= "Content-Type: multipart/alternative; boundary=\"----=MIME_BOUNDRY_message_parts\"\n"; $message = "------=MIME_BOUNDRY_message_parts\n"; $message .= "Content-Type: text/html; charset=\"iso-8859-1\"\n"; $message .= "Content-Transfer-Encoding: quoted-printable\n"; $message .= "\n"; /* Add our message, in this case it's plain text. You could also add HTML by changing the Content-Type to text/html */ $message .= "<strong>TheNannyGroup.com</strong> - You have a new nanny applicant!<br><br> <strong>Personal Information</strong><br><br> First Name = {$firstname} Last Name = {$lastname} Phone = {$phone} Fax = {$fax} Address = {$address} Unit = {$address2} State = {$state} City = {$city} Zip = {$zip} Email = {<a href=\"mailto:$email\">$email</a>}<br><br><br> <strong>Employment Information</strong><br><br> Date Available = {$available} Live In = {$livein} Overnights = {$overnights} Travel = {$travel} Full Time = {$fulltime} Part Time = {$parttime}<br><br><br> <strong>Other Information</strong><br><br> Comment = {$comment}\n"; $message .= "\n"; $message .= "------=MIME_BOUNDRY_message_parts--\n"; $message .= "\n"; $message .= "------=MIME_BOUNDRY_main_message\n"; $message .= "Content-Type: application/octet-stream;\n\tname=\"" . $resume_name . "\"\n"; $message .= "Content-Transfer-Encoding: base64\n"; $message .= "Content-Disposition: attachment;\n\tfilename=\"" . $resume_name . "\"\n\n"; $message .= $data; //The base64 encoded message $message .= "\n"; $message .= "------=MIME_BOUNDRY_main_message--\n" //Send the message mail("to_name<$to_email>", $subject, $message, $headers); print "Mail Sent. Thank you for your interest."; } } Enter_New_Entry($firstname,$lastname,$phone,$fax,$address,$address2,$state,$city,$zip,$email,$available,$livein,$overnights,$travel,$fulltime,$parttime,$comment,$agreement); function Enter_New_Entry ($firstname,$lastname,$phone,$fax,$address,$address2,$state,$city,$zip,$email,$available,$livein,$overnights,$travel,$fulltime,$parttime,$comment,$agreement) { $cnx = mysql_connect("localhost","**********","**********"); if (!$cnx) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db('**********', $cnx); if (!$db_selected) { die ('Can\'t use Records Database : ' . mysql_error()); } $SQL_Exec_String = "Insert Into applicants (firstname, lastname, phone, fax, address, address2, state, city, zip, email, available, livein, overnights, travel, fulltime, parttime, comment, agreement) Values ('$firstname', '$lastname', '$phone', '$fax', '$address', '$address2', '$state', '$city', '$zip', '$email', '$available', '$livein', '$overnights', '$travel', '$fulltime', '$parttime', '$comment', '$agreement')"; $cur = mysql_query($SQL_Exec_String); if (!$cur) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } mysql_close($cnx); header("location: http://www.thenannygroup.com/verify.php"); } ?> I thought it was just unescaped quotes on line 96, but i tried to escape them, and it made no difference. you guys see anything, or have a better direction to point me in? Thanks Croix Quote Link to comment https://forums.phpfreaks.com/topic/73967-php-mail-function-sending-attachments/ Share on other sites More sharing options...
gerkintrigg Posted October 19, 2007 Share Posted October 19, 2007 try replacing the print command with an echo statement and see if that works. So replace the word "print" with "echo". I think print commands might need (brackets) - I wouldn't know... I never use Print. Quote Link to comment https://forums.phpfreaks.com/topic/73967-php-mail-function-sending-attachments/#findComment-373329 Share on other sites More sharing options...
croix Posted October 19, 2007 Author Share Posted October 19, 2007 didnt make a difference. I will be removing that entirely once the script is working. Quote Link to comment https://forums.phpfreaks.com/topic/73967-php-mail-function-sending-attachments/#findComment-373333 Share on other sites More sharing options...
steve448 Posted October 19, 2007 Share Posted October 19, 2007 Your missing a semi colon ; at the end of your $message just before the mail function Quote Link to comment https://forums.phpfreaks.com/topic/73967-php-mail-function-sending-attachments/#findComment-373514 Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 I advise getting rid of what you have and using OOP (phpmailer is a good example) instead of what you have. What you have is hard to read, insecure, and not easy to maintain if you needed to update it later on down the road. You could repeat what you have done there in half of the code or better (10 times more readable, and easier to upgrade) by using a class, or atleast restructuring the code. Quote Link to comment https://forums.phpfreaks.com/topic/73967-php-mail-function-sending-attachments/#findComment-373629 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.