rachieann Posted November 17, 2009 Share Posted November 17, 2009 I found this original coding somewhere and changed it to suit my needs: form.php: <div id="form"> <form action="email.php" enctype="multipart/form-data" method="post" onsubmit="document.getElementById('container0').style.display=''; document.getElementById('container2').style.display='none'; progress(); return true;"> <fieldset id="fieldset"> <label for="eventname">Event Name<span style="color: red;">*</span>:</label> <input <?php if (!empty ($hidden)) { if (empty ($eventname)) { print 'style="background: pink;"'; } } ?> class="form_elements" id="eventname" type="text" name="eventname" value="<?php print "$eventname"; ?>" tabindex="1" /> <br /> <label for="eventdate">Event Date<span style="color: red;">*</span>:</label> <input <?php if (!empty ($hidden)) { if (empty ($eventdate)) { print 'style="background: pink;"'; } } ?> class="form_elements" id="eventdate" type="text" name="yeventdate" value="<?php print "$eventdate"; ?>" tabindex="1" /> <br /> <label for="eventtime">Event Time(s)<span style="color: red;">*</span>:</label> <input <?php if (!empty ($hidden)) { if (empty ($eventtime)) { print 'style="background: pink;"'; } } ?> class="form_elements" id="eventtime" type="text" name="eventtime" value="<?php print "$eventtime"; ?>" tabindex="1" /> <br /> <label for="eventlocation">Event Location<span style="color: red;">*</span>:</label> <input <?php if (!empty ($hidden)) { if (empty ($eventlocation)) { print 'style="background: pink;"'; } } ?> class="form_elements" id="eventlocation" type="text" name="eventlocation" value="<?php print "$eventlocation"; ?>" tabindex="1" /> <br /> <label for="locationaddress">Location Address<span style="color: red;">*</span>:</label> <input <?php if (!empty ($hidden)) { if (empty ($locationaddress)) { print 'style="background: pink;"'; } } ?> class="form_elements" id="locationaddress" type="text" name="locationaddress" value="<?php print "$locationaddress"; ?>" tabindex="1" /> <br /> <label for="citystate">City/State<span style="color: red;">*</span>:</label> <input <?php if (!empty ($hidden)) { if (empty ($citystate)) { print 'style="background: pink;"'; } } ?> class="form_elements" id="citystate" type="text" name="citystate" value="<?php print "$citystate"; ?>" tabindex="1" /> <br /> <label for="eventcost">Event Cost<span style="color: red;">*</span>:</label> <input <?php if (!empty ($hidden)) { if (empty ($eventcost)) { print 'style="background: pink;"'; } } ?> class="form_elements" id="eventcost" type="text" name="eventcost" value="<?php print "$eventcost"; ?>" tabindex="1" /> <br /> <label for="eventdescription">Event Description<span style="color: red;">*</span>:</label> <textarea <?php if (!empty ($hidden)) { if (empty ($eventdescription)) { print 'style="background: pink;"'; } } ?>class="form_elements" id="eventdescription" name="eventdescription" cols="19" rows="5" tabindex="1"><?php print "$eventdescription"; ?></textarea> <br /> <label for="eventwebsite">Event website:</label> <input class="form_elements" id="eventwebsite" type="text" name="eventwebsite" value="<?php print "$eventwebsite"; ?>" tabindex="1" /> <br /> <label for="eventemail">Event email address:</label> <input class="form_elements" id="eventemail" type="text" name="eventemail" value="<?php print "$eventemail"; ?>" tabindex="1" /> <br /> <label for="eventphone">Event phone number:</label> <input class="form_elements" id="eventphone" type="text" name="eventphone" value="<?php print "$eventphone"; ?>" tabindex="1" /> <br /><br /> <label for="fileatt">Attach image:</label> <input id="fileatt" type="file" name="fileatt" tabindex="1" /> <br /><br /> The following information will not be posted unless indicated above: <br /> <label for="yourname">Your Name<span style="color: red;">*</span>:</label> <input <?php if (!empty ($hidden)) { if (empty ($yourname)) { print 'style="background: pink;"'; } } ?> class="form_elements" id="yourname" type="text" name="yourname" value="<?php print "$yourname"; ?>" tabindex="1" /> <br /> <label for="youremail">Your Email<span style="color: red;">*</span>:</label> <input <?php if (!empty ($hidden)) { if (empty ($youremail)) { print 'style="background: pink;"'; } } ?> class="form_elements" id="youremail" type="text" name="youremail" value="<?php print "$youremail"; ?>" tabindex="1" /> <br /> <label for="confirm_email">Confirm e-mail<span style="color: red;">*</span>:</label> <input <?php if (!empty ($hidden)) { if (empty ($confirm_email)) { print 'style="background: pink;"'; } } ?> class="form_elements" id="confirm_email" type="text" name="confirm_email" value="<?php print "$confirm_email"; ?>" tabindex="1" /> <br /><br /> <input type="hidden" name="hidden" value="1" /><br /> <label for="submit"><span style="color: red;">*</span> Required fields.</label> <input id="submit" type="submit" value="Submit" tabindex="1" /> </fieldset> </form> </div> email.php: <?php ob_start(); $to = 'rhouserdesigns@gmail.com'; $keys = array('eventname', 'eventdate', 'eventtime', 'eventlocation', 'locationaddress', 'citystate', 'eventcost', 'eventdescription', 'yourname', 'youremail', 'confirm_email', 'hidden'); foreach($keys as $key) {$$key = isset($_POST[$key]) ? $_POST[$key] : null ;} print (' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=iso- 8859-1" /> <title>Email</title> <script type="text/javascript"> /*<![CDATA[*/ function progress(){ intWidth = parseInt(document.getElementById("container1").style.width) + 1; if(intWidth <= 400){ document.getElementById("container1").style.width = intWidth+"px"; }else{ document.getElementById("container1").style.width = 0; } setTimeout("progress()",300); } /*]]>*/ </script> </head> <body> '); //Make sure email and confirm email are the same if (!empty ($hidden)) { if ($youremail == $confirm_email) { }else{ $youremail = ''; $confirm_email = ''; } } //Do a reg_ex check on the email if (!empty ($hidden)) { $regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-] +)*(\.[a-z]{2,4})$"; if (eregi($regexp, $youremail)) { }else{ $youremail = ''; $confirm_email = ''; } } // End of email checking if (empty ($hidden)) { print ('<div id="container2"> <h1 id="content_h1"><a name="text"> E-mail </a></h1> <p>Please use the following form to e-mail us:</p> '); include ("form.php"); print ('</div> <div id="container0" style="display: none;"> <p style="font-size: 15pt; font-family: sans-serif; color:#fd6700; background:#fff;"> Loading... </p> <div id="container1" style="width:0px; height:5px; background- color:#fd6700; margin-top:0px; text-align: left;"></div> <p>Please be patient while your data is processed. This may take a few moments especially if you are uploading a file.</p> </div> '); } if (!empty ($hidden)) { if ($_FILES['fileatt']['error'] == 1){ print ('<h1 id="content_h1"><a name="text">There has been an error</a></h1> <p>The maximum file size that can be uploaded using this form is 2 megabytes. </p>'); }elseif ( (!empty ($eventname)) && (!empty ($eventdate)) && (!empty ($eventtime)) && (!empty ($eventlocation)) && (!empty ($locationaddress)) && (!empty ($citystate)) && (!empty ($eventcost)) && (!empty ($eventdescription)) && (!empty ($yourname)) && (!empty ($youremail))) { // Get html message content $form_data = "<p><span class=\"bold\">Event Name:</span> $eventname< \n\n "; $form_data = "<p><span class=\"bold\">Event Date:</span> $eventdate< \n\n "; $form_data = "<p><span class=\"bold\">Event Time(s):</span> $eventtime< \n\n "; $form_data = "<p><span class=\"bold\">Event Location:</span> $eventlocation< \n\n "; $form_data = "<p><span class=\"bold\">Location Address:</span> $locationaddress< \n\n "; $form_data = "<p><span class=\"bold\">City/State:</span> $citystate< \n\n "; $form_data = "<p><span class=\"bold\">Event Cost:</span> $eventcost< \n\n "; $form_data = "<p><span class=\"bold\">Event Description:</span> $eventdescription< \n\n "; $form_data = "<p><span class=\"bold\">Event website:</span> $eventwebsite< \n\n "; $form_data = "<p><span class=\"bold\">Event email address:</span> $eventemail< \n\n "; $form_data = "<p><span class=\"bold\">Event phone number:</span> $eventphone< \n\n "; $form_data = "<p><span class=\"bold\">Submitted by:</span> $yourname< \n\n "; $form_data = "<p><span class=\"bold\">Their email address:</span> $youremail"; $message = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \n" . " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1- strict.dtd\"> \n" . "<html xmlns=\"http://www.w3.org/1999/xhtml\"> \n" . "<head> \n" . " <meta http-equiv=\"content-type\" content= \n" . " \"text/html; charset=iso-8859-1\" /> \n" . "<style type=\"text/css\"> \n" . "body { font-size: 9pt; font-family: verdana, sans -serif; color: #000; background:#fff; } \n" . ".bold { font-weight: bold; } \n" . "</style> \n" . "</head> \n" . "<body>$form_data \n" . "</body> \n" . "</html> \n\n"; // Obtain file upload vars $fileatt = $_FILES['fileatt']['tmp_name']; $fileatt_type = $_FILES['fileatt']['type']; $fileatt_name = $_FILES['fileatt']['name']; $headers = "From: $from"; if (is_uploaded_file($fileatt)) { // Read the file to be attached ('rb' = read binary) $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); // Generate a boundary string $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // Add the headers for a file attachment $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; // Add a multipart boundary above the html message $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; // Base64 encode the file data $data = chunk_split(base64_encode($data)); //We now have everything we need to write the portion of the message that contains the file attachment. Here's the code: // Add file attachment to the message $message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64 \n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; }else{ // Generate a boundary string $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // Add the headers for a file attachment $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; // Add a multipart boundary above the html message $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; } //That completes the modifications necessary to accommodate a file attachment. We can now send the message with a quick call to mail: // Send the message mail($to, "$subject, $message, $headers); $body = "Dear $yourname, \n\nThank you for your event submission. \n \n"; mail ($youremail, "Re: $subject", $body, 'From:rhouserdesign@gmail.com'); print ('<h1 id="content_h1"><a name="text"> Thank you </a></h1> <p>Thank you for your event submission. You will receive an automatic e-mail immediately confirming the reception of your email.</p>'); }else{ print ('<h1 id="content_h1"><a name="text">There has been an error</a></h1> <p>Please fill in all the compulsory fields correctly and then resubmit the form. Thank you.</p>'); include ("form.php"); } } // This is the end of the insert print (' </div> </body> </html> '); ob_end_flush(); ?> Now my problem: When I test the form I get this error: Parse error: syntax error, unexpected T_STRING in email.php on line 186 Can anyone help me out here? I have tried everything I can think of. Quote Link to comment https://forums.phpfreaks.com/topic/181911-error-message-with-email-form-with-fileimage-attachment-need-help/ Share on other sites More sharing options...
premiso Posted November 17, 2009 Share Posted November 17, 2009 that contains the file attachment. Here's the code: You do not have that commented out. Make it like this: //that contains the file attachment. Here's the code: And hopefully that fixes your syntax error. Quote Link to comment https://forums.phpfreaks.com/topic/181911-error-message-with-email-form-with-fileimage-attachment-need-help/#findComment-959457 Share on other sites More sharing options...
mrMarcus Posted November 17, 2009 Share Posted November 17, 2009 another one below that: //That completes the modifications necessary to accommodate a file attachment. We can now send the message with a quick call to mail: every line that is a comment needs to be properly commented using: <?php #comment //comment /* * comment */ ?> Quote Link to comment https://forums.phpfreaks.com/topic/181911-error-message-with-email-form-with-fileimage-attachment-need-help/#findComment-959460 Share on other sites More sharing options...
rachieann Posted November 17, 2009 Author Share Posted November 17, 2009 @premiso I added what you told me to add: <?php ob_start(); $to = 'rhouserdesigns@gmail.com'; $keys = array('eventname', 'eventdate', 'eventtime', 'eventlocation', 'locationaddress', 'citystate', 'eventcost', 'eventdescription', 'yourname', 'youremail', 'confirm_email', 'hidden'); foreach($keys as $key) {$$key = isset($_POST[$key]) ? $_POST[$key] : null ;} print (' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=iso- 8859-1" /> <title>Email</title> <script type="text/javascript"> /*<![CDATA[*/ function progress(){ intWidth = parseInt(document.getElementById("container1").style.width) + 1; if(intWidth <= 400){ document.getElementById("container1").style.width = intWidth+"px"; }else{ document.getElementById("container1").style.width = 0; } setTimeout("progress()",300); } /*]]>*/ </script> </head> <body> '); //Make sure email and confirm email are the same if (!empty ($hidden)) { if ($youremail == $confirm_email) { }else{ $youremail = ''; $confirm_email = ''; } } //Do a reg_ex check on the email if (!empty ($hidden)) { $regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-] +)*(\.[a-z]{2,4})$"; if (eregi($regexp, $youremail)) { }else{ $youremail = ''; $confirm_email = ''; } } // End of email checking if (empty ($hidden)) { print ('<div id="container2"> <h1 id="content_h1"><a name="text"> E-mail </a></h1> <p>Please use the following form to e-mail us:</p> '); include ("form.php"); print ('</div> <div id="container0" style="display: none;"> <p style="font-size: 15pt; font-family: sans-serif; color:#fd6700; background:#fff;"> Loading... </p> <div id="container1" style="width:0px; height:5px; background- color:#fd6700; margin-top:0px; text-align: left;"></div> <p>Please be patient while your data is processed. This may take a few moments especially if you are uploading a file.</p> </div> '); } if (!empty ($hidden)) { if ($_FILES['fileatt']['error'] == 1){ print ('<h1 id="content_h1"><a name="text">There has been an error</a></h1> <p>The maximum file size that can be uploaded using this form is 2 megabytes. </p>'); }elseif ( (!empty ($eventname)) && (!empty ($eventdate)) && (!empty ($eventtime)) && (!empty ($eventlocation)) && (!empty ($locationaddress)) && (!empty ($citystate)) && (!empty ($eventcost)) && (!empty ($eventdescription)) && (!empty ($yourname)) && (!empty ($youremail))) { // Get html message content $form_data = "<p><span class=\"bold\">Event Name:</span> $eventname< \n\n "; $form_data = "<p><span class=\"bold\">Event Date:</span> $eventdate< \n\n "; $form_data = "<p><span class=\"bold\">Event Time(s):</span> $eventtime< \n\n "; $form_data = "<p><span class=\"bold\">Event Location:</span> $eventlocation< \n\n "; $form_data = "<p><span class=\"bold\">Location Address:</span> $locationaddress< \n\n "; $form_data = "<p><span class=\"bold\">City/State:</span> $citystate< \n\n "; $form_data = "<p><span class=\"bold\">Event Cost:</span> $eventcost< \n\n "; $form_data = "<p><span class=\"bold\">Event Description:</span> $eventdescription< \n\n "; $form_data = "<p><span class=\"bold\">Event website:</span> $eventwebsite< \n\n "; $form_data = "<p><span class=\"bold\">Event email address:</span> $eventemail< \n\n "; $form_data = "<p><span class=\"bold\">Event phone number:</span> $eventphone< \n\n "; $form_data = "<p><span class=\"bold\">Submitted by:</span> $yourname< \n\n "; $form_data = "<p><span class=\"bold\">Their email address:</span> $youremail"; $message = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \n" . " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1- strict.dtd\"> \n" . "<html xmlns=\"http://www.w3.org/1999/xhtml\"> \n" . "<head> \n" . " <meta http-equiv=\"content-type\" content= \n" . " \"text/html; charset=iso-8859-1\" /> \n" . "<style type=\"text/css\"> \n" . "body { font-size: 9pt; font-family: verdana, sans -serif; color: #000; background:#fff; } \n" . ".bold { font-weight: bold; } \n" . "</style> \n" . "</head> \n" . "<body>$form_data \n" . "</body> \n" . "</html> \n\n"; // Obtain file upload vars $fileatt = $_FILES['fileatt']['tmp_name']; $fileatt_type = $_FILES['fileatt']['type']; $fileatt_name = $_FILES['fileatt']['name']; $headers = "From: $from"; if (is_uploaded_file($fileatt)) { // Read the file to be attached ('rb' = read binary) $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); // Generate a boundary string $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // Add the headers for a file attachment $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; // Add a multipart boundary above the html message $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; // Base64 encode the file data $data = chunk_split(base64_encode($data)); //We now have everything we need to write the portion of the message //that contains the file attachment. Here's the code: // Add file attachment to the message $message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64 \n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; }else{ // Generate a boundary string $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // Add the headers for a file attachment $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; // Add a multipart boundary above the html message $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; } //That completes the modifications necessary to accommodate a file attachment. We can now send the message with a quick call to mail: // Send the message mail($to, "$subject, $message, $headers); $body = "Dear $yourname, \n\nThank you for your event submission. \n \n"; mail ($youremail, "Re: $subject", $body, 'From:rhouserdesign@gmail.com'); print ('<h1 id="content_h1"><a name="text"> Thank you </a></h1> <p>Thank you for your event submission. You will receive an automatic e-mail immediately confirming the reception of your email.</p>'); }else{ print ('<h1 id="content_h1"><a name="text">There has been an error</a></h1> <p>Please fill in all the compulsory fields correctly and then resubmit the form. Thank you.</p>'); include ("form.php"); } } // This is the end of the insert print (' </div> </body> </html> '); ob_end_flush(); ?> but now I'm getting this error: Parse error: syntax error, unexpected T_STRING in email.php on line 216 Quote Link to comment https://forums.phpfreaks.com/topic/181911-error-message-with-email-form-with-fileimage-attachment-need-help/#findComment-959534 Share on other sites More sharing options...
mrMarcus Posted November 18, 2009 Share Posted November 18, 2009 // Send the message mail($to, "$subject, $message, $headers); remove the " next to $subject Quote Link to comment https://forums.phpfreaks.com/topic/181911-error-message-with-email-form-with-fileimage-attachment-need-help/#findComment-959698 Share on other sites More sharing options...
rachieann Posted November 18, 2009 Author Share Posted November 18, 2009 Still getting the same error... Sound I just scrap this and start again? And if so, does anyone have any good suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/181911-error-message-with-email-form-with-fileimage-attachment-need-help/#findComment-959775 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.