parse error?

  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Joined: Aug 04, 2008
  • Posts: 846
  • Status: Offline

Post July 1st, 2009, 7:03 pm

I am receiving this error on a php script:
Code: [ Select ]
Parse error: parse error in C:\USR\bin\wamp\dir\example.php on line 11


this is line 11:
Code: [ Select ]
$mail_prefix = 'A quote request was sent to you from ' . $_POST['firstname'] . ' ' . $_POST['lastname'] . '\r\n <hr />';


Anyone know what this is all about?
Use your words like arrows to shoot toward your goal.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post July 1st, 2009, 7:03 pm

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Joined: Dec 20, 2002
  • Posts: 8926
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Post July 1st, 2009, 7:22 pm

What are a few of the lines that precede the line you gave us? Did you forget to close any lines with semicolons?

Also this part:

Code: [ Select ]
'\r\n <hr />'


I am fairly certain the \r\n (the escape sequences) won't be interpreted correctly unless you put them in double quotes as:

Code: [ Select ]
"\r\n <hr />"


As shown here:

http://www.php.net/manual/en/language.t ... tax.double

Although that still shouldn't result in your Parse error code.
Ozzu Hosting - Want your website on a fast server like Ozzu?
  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Joined: Aug 04, 2008
  • Posts: 846
  • Status: Offline

Post July 1st, 2009, 7:41 pm

wow, that was simple enough. Didn't have a semicolon on the line above.
Use your words like arrows to shoot toward your goal.
  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Joined: Aug 04, 2008
  • Posts: 846
  • Status: Offline

Post July 1st, 2009, 8:02 pm

no, wait...still getting the error
Use your words like arrows to shoot toward your goal.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Joined: Dec 20, 2002
  • Posts: 8926
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Post July 1st, 2009, 8:13 pm

If you are still having the error can you show us the code all around that line? Is it the same error?
Ozzu Hosting - Want your website on a fast server like Ozzu?
  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Joined: Aug 04, 2008
  • Posts: 846
  • Status: Offline

Post July 1st, 2009, 8:13 pm

Code: [ Select ]
 
<?php
/* Some required variables to configure this page */
include("../../bin/php/php5.2.9-2/PEAR/Structures/Mail.php");
// Variables not to be sent to you
$blocked = array('submit1');
 
// The email address the result of the form would be sent to.
$adm_email = 'your_email@your_host.com';
 
// The prefix to the mail
$mail_prefix = 'A quote request for selection' . $_POST['service'] . ' was sent to you from ' . $_POST['firstname'] . ' ' . $_POST['lastname'] . "\r\n" . ' <hr />';
 
// The post (signature) to the mail
$mail_post = null;
 
// The title for the message
$title = 'A ' . $_POST['service'] . ' request was sent to you from ' . $_POST['firstname'] . ' ' . $_POST['lastname'];
 
/* The actual code body for sending */
 
// Initiating the body var
$body = $mail_prefix;
 
// Initiating some numeric values that would be incremented in the following loop
$blocked_num = 0;
 
// Building the body for the mail
foreach($_POST as $field_name => $field_value)
{
    // Building the body for the mail with the correct fields
    if($field_name != $blocked[$blocked_num])
        $body .= "<strong>{$field_name}</strong>: {$_POST[$field_name]}<br />\r\n";
 
    // Initiating the blocked num counter if needed
    if(count($blocked) < $blocked_num)
        ++$blocked_num;
}
 
// Ending the body var
$body .= $mail_post;
 
// Trimming the ends of body from any unneeded white spaces
$body = trim($body);
 
// Requiring the SMTP class
require_once 'mail.php';
 
// Initiating the mail object
$mail = new mail();
 
// Sending the message
if(new mail($_POST['email'], $title, $body, true))
    echo 'The mail was successfully sent. Thank you for your time!';
else
    echo 'There was an error in the mailling service.';
?>
 
  1.  
  2. <?php
  3. /* Some required variables to configure this page */
  4. include("../../bin/php/php5.2.9-2/PEAR/Structures/Mail.php");
  5. // Variables not to be sent to you
  6. $blocked = array('submit1');
  7.  
  8. // The email address the result of the form would be sent to.
  9. $adm_email = 'your_email@your_host.com';
  10.  
  11. // The prefix to the mail
  12. $mail_prefix = 'A quote request for selection' . $_POST['service'] . ' was sent to you from ' . $_POST['firstname'] . ' ' . $_POST['lastname'] . "\r\n" . ' <hr />';
  13.  
  14. // The post (signature) to the mail
  15. $mail_post = null;
  16.  
  17. // The title for the message
  18. $title = 'A ' . $_POST['service'] . ' request was sent to you from ' . $_POST['firstname'] . ' ' . $_POST['lastname'];
  19.  
  20. /* The actual code body for sending */
  21.  
  22. // Initiating the body var
  23. $body = $mail_prefix;
  24.  
  25. // Initiating some numeric values that would be incremented in the following loop
  26. $blocked_num = 0;
  27.  
  28. // Building the body for the mail
  29. foreach($_POST as $field_name => $field_value)
  30. {
  31.     // Building the body for the mail with the correct fields
  32.     if($field_name != $blocked[$blocked_num])
  33.         $body .= "<strong>{$field_name}</strong>: {$_POST[$field_name]}<br />\r\n";
  34.  
  35.     // Initiating the blocked num counter if needed
  36.     if(count($blocked) < $blocked_num)
  37.         ++$blocked_num;
  38. }
  39.  
  40. // Ending the body var
  41. $body .= $mail_post;
  42.  
  43. // Trimming the ends of body from any unneeded white spaces
  44. $body = trim($body);
  45.  
  46. // Requiring the SMTP class
  47. require_once 'mail.php';
  48.  
  49. // Initiating the mail object
  50. $mail = new mail();
  51.  
  52. // Sending the message
  53. if(new mail($_POST['email'], $title, $body, true))
  54.     echo 'The mail was successfully sent. Thank you for your time!';
  55. else
  56.     echo 'There was an error in the mailling service.';
  57. ?>
  58.  


Here's the HTML for the form if it's of any relevance:
Code: [ Select ]
<div id="form1" align="left">
<h2 align="center">Get A Quote!</h2>
<form id="form" action="sendemail.php" method="post">
<table width="90%" border="0" cellspacing="0" cellpadding="0">
<tr>
    <td>First Name:</td>
    <td><input type="text" name="firstname" size="51" /></td>
</tr>
<tr>
    <td>Last Name:</td>
    <td><input type="text" name="lastname" size="51" /></td>
</tr>
<tr>
    <td>Email Address:</td>
    <td><input type="text" name="email" size="51" /></td>
</tr>
<tr>
    <td>Service:</td>
    <td><select name="service" id="service">
     <option value="1">Website Design</option>
     <option value="2">Website Hosting</option>
     <option value="3">Email Hosting</option>
    </select></td>
</tr>
<tr>
    <td>Comments:</td>
    <td><textarea name="textarea" cols="54"></textarea></td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td><div align="right">
     <input type="submit" name="submit1" id="submit1" value="Submit">
    </div></td>
</tr>
</table>
</form>
</div>
  1. <div id="form1" align="left">
  2. <h2 align="center">Get A Quote!</h2>
  3. <form id="form" action="sendemail.php" method="post">
  4. <table width="90%" border="0" cellspacing="0" cellpadding="0">
  5. <tr>
  6.     <td>First Name:</td>
  7.     <td><input type="text" name="firstname" size="51" /></td>
  8. </tr>
  9. <tr>
  10.     <td>Last Name:</td>
  11.     <td><input type="text" name="lastname" size="51" /></td>
  12. </tr>
  13. <tr>
  14.     <td>Email Address:</td>
  15.     <td><input type="text" name="email" size="51" /></td>
  16. </tr>
  17. <tr>
  18.     <td>Service:</td>
  19.     <td><select name="service" id="service">
  20.      <option value="1">Website Design</option>
  21.      <option value="2">Website Hosting</option>
  22.      <option value="3">Email Hosting</option>
  23.     </select></td>
  24. </tr>
  25. <tr>
  26.     <td>Comments:</td>
  27.     <td><textarea name="textarea" cols="54"></textarea></td>
  28. </tr>
  29. <tr>
  30.     <td>&nbsp;</td>
  31.     <td><div align="right">
  32.      <input type="submit" name="submit1" id="submit1" value="Submit">
  33.     </div></td>
  34. </tr>
  35. </table>
  36. </form>
  37. </div>
Use your words like arrows to shoot toward your goal.
  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post July 1st, 2009, 8:37 pm

Try the following... Don't know if that would fix the error, but I know that it would save some processing power (I'm pretty sure).
Code: [ Select ]
<?php
/* Some required variables to configure this page */

// Variables not to be sent to you
$blocked = array('submit1');

// The email address the result of the form would be sent to.
$adm_email = 'your_email@your_host.com';

// The prefix to the mail
$mail_prefix = "A quote request for selection ({$_POST['service']}) was sent to you from {$_POST['firstname']} {$_POST['lastname']}\r\n <hr />";

// The post (signature) to the mail
$mail_post = null;

// The title for the message
$title = "A {$_POST['service']} request was sent to you from {$_POST['firstname']} " . $_POST['lastname'];

/* The actual code body for sending */

// Initiating the body var
$body = $mail_prefix;

// Building the body for the mail with the correct fields
foreach($_POST as $field_name => $field_value)
    if(!in_array($field_name, $blocked))
        $body .= "<strong>{$field_name}</strong>: {$field_value}<br />\r\n";

// Ending the body var
$body .= $mail_post;

// Trimming the ends of body from any unneeded white spaces
$body = trim($body);

// Requiring the SMTP class
require_once 'mail.php';

// Initiating the mail object
$mail = new mail();

// Sending the message
if(new mail($_POST['email'], $title, $body, true))
    echo 'The mail was successfully sent. Thank you for your time!';
else
    echo 'There was an error in the mailling service.';
?>
  1. <?php
  2. /* Some required variables to configure this page */
  3. // Variables not to be sent to you
  4. $blocked = array('submit1');
  5. // The email address the result of the form would be sent to.
  6. $adm_email = 'your_email@your_host.com';
  7. // The prefix to the mail
  8. $mail_prefix = "A quote request for selection ({$_POST['service']}) was sent to you from {$_POST['firstname']} {$_POST['lastname']}\r\n <hr />";
  9. // The post (signature) to the mail
  10. $mail_post = null;
  11. // The title for the message
  12. $title = "A {$_POST['service']} request was sent to you from {$_POST['firstname']} " . $_POST['lastname'];
  13. /* The actual code body for sending */
  14. // Initiating the body var
  15. $body = $mail_prefix;
  16. // Building the body for the mail with the correct fields
  17. foreach($_POST as $field_name => $field_value)
  18.     if(!in_array($field_name, $blocked))
  19.         $body .= "<strong>{$field_name}</strong>: {$field_value}<br />\r\n";
  20. // Ending the body var
  21. $body .= $mail_post;
  22. // Trimming the ends of body from any unneeded white spaces
  23. $body = trim($body);
  24. // Requiring the SMTP class
  25. require_once 'mail.php';
  26. // Initiating the mail object
  27. $mail = new mail();
  28. // Sending the message
  29. if(new mail($_POST['email'], $title, $body, true))
  30.     echo 'The mail was successfully sent. Thank you for your time!';
  31. else
  32.     echo 'There was an error in the mailling service.';
  33. ?>


[EDIT:] I edited the above code I posted a little while ago. I have tested it and it works fine for me... creates the body okay (Keep in mind that whatever you name your fields, that is what your field names in the body would be called).
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Joined: Aug 04, 2008
  • Posts: 846
  • Status: Offline

Post July 1st, 2009, 9:49 pm

awesome. How would I redirect back to my home page if the mail sent?
Use your words like arrows to shoot toward your goal.
  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post July 1st, 2009, 10:02 pm

Change
Code: [ Select ]
// Sending the message
if(new mail($_POST['email'], $title, $body, true))
    echo 'The mail was successfully sent. Thank you for your time!';
else
    echo 'There was an error in the mailing service.';
  1. // Sending the message
  2. if(new mail($_POST['email'], $title, $body, true))
  3.     echo 'The mail was successfully sent. Thank you for your time!';
  4. else
  5.     echo 'There was an error in the mailing service.';
to
Code: [ Select ]
// Sending the message
if(new mail($_POST['email'], $title, $body, true))
{
    echo 'The mail was successfully sent. Thank you for your time!';
    ob_flush();
    flush();
    sleep(5); // Sleep for 5 seconds before redirecting
    header("LOCATION: index.php");
}
else
    echo 'There was an error in the mailing service.';
  1. // Sending the message
  2. if(new mail($_POST['email'], $title, $body, true))
  3. {
  4.     echo 'The mail was successfully sent. Thank you for your time!';
  5.     ob_flush();
  6.     flush();
  7.     sleep(5); // Sleep for 5 seconds before redirecting
  8.     header("LOCATION: index.php");
  9. }
  10. else
  11.     echo 'There was an error in the mailing service.';
Try that... if that doesn't show the text, then switch the order of the two flush's.
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Joined: Aug 04, 2008
  • Posts: 846
  • Status: Offline

Post July 1st, 2009, 11:32 pm

hmmm, that's causing this problem:
Code: [ Select ]
Warning: Cannot modify header information - headers already sent by (output started at C:\USR\bin\wamp\www\voltec\sendemail.php:55) in C:\USR\bin\wamp\www\voltec\sendemail.php on line 58
Use your words like arrows to shoot toward your goal.
  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post July 1st, 2009, 11:55 pm

Change the following:
Code: [ Select ]
header("LOCATION: index.php");
to
Code: [ Select ]
echo "<script language=\"JavaScript\">window.location=\"index.php\";</script>";
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Joined: Dec 20, 2002
  • Posts: 8926
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Post July 2nd, 2009, 12:17 am

If you don't want to use Javascript you can also use a meta refresh. Might be more reliable jsut in case someone has Javascript disabled.
Ozzu Hosting - Want your website on a fast server like Ozzu?
  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post July 2nd, 2009, 11:12 am

Bigwebmaster wrote:
If you don't want to use Javascript you can also use a meta refresh. Might be more reliable jsut in case someone has Javascript disabled.

Does it work in the body section?
"Bring forth therefore fruits meet for repentance:" Matthew 3:8

Post Information

  • Total Posts in this topic: 13 posts
  • Users browsing this forum: No registered users and 103 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.