942,520 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 4430
  • PHP RSS
Jun 19th, 2010
0

PHP Parse error

Expand Post »
Please help?

I am getting the following error when executing a mass mailing script that contains HTML as the mail content:
Parse error: syntax error, unexpected '>' in ... on line 14
If I remove lines 14 to 27 (from <style> to </style>) I get the following error:
Parse error: syntax error, unexpected T_STRING in ... on line 14

Here is the code

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. include_once "connect_to_mysql.php";
  3. $sql = mysql_query("SELECT * FROM mail WHERE field_9='0' AND field_8='max' LIMIT 20");
  4. $numRows = mysql_num_rows($sql); // Added for "End Campaign Check" at the bottom of this file(not shown on the video)
  5. $mail_body = '';
  6. while($row = mysql_fetch_array($sql)){
  7. $id = $row["id"];
  8. $email = $row["field_4"];
  9. $name = $row["field_5"];
  10.  
  11. $mail_body = '
  12. <html>
  13. <body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0" bgcolor='#505050' >
  14. <STYLE>
  15. .headerTop { background-color:#ffffff; border-top:0px solid #000000; border-bottom:1px solid #FFFFFF; text-align:center; }
  16. .adminText { font-size:10px; color:#ff7700; line-height:200%; font-family:verdana; text-decoration:none; }
  17. .headerBar { background-color:#e0e0e0; border-top:0px solid #333333; border-bottom:10px solid #FFFFFF; }
  18. .title { font-size:20px; font-weight:bold; color:#ff7700; font-family:arial; line-height:110%; }
  19. .subTitle { font-size:11px; font-weight:normal; color:#666666; font-style:italic; font-family:arial; }
  20. td { font-size:12px; color:#000000; line-height:150%; font-family:trebuchet ms; }
  21. .sideColumn { background-color:#e0e0e0; border-right:1px solid #505050; text-align:left; }
  22. .sideColumnText { font-size:11px; font-weight:normal; color:#999999; font-family:arial; line-height:150%; }
  23. .sideColumnTitle { font-size:15px; font-weight:bold; color:#333333; font-family:arial; line-height:150%; }
  24. .footerRow { background-color:#505050; border-top:10px solid #FFFFFF; }
  25. .footerText { font-size:10px; color:#ffffff; line-height:100%; font-family:verdana; }
  26. a { color:#FF6600; color:#FF6600; color:#FF6600; }
  27. </STYLE>
  28. <table width="100%" cellpadding="10" cellspacing="0" bgcolor='#505050' >
  29. <tr>
  30. <td valign="top" align="center">
  31. <table width="600" cellpadding="0" cellspacing="0">
  32. <tr>
  33. <td style="background-color:#ffffff;border-top:0px solid #000000;border-bottom:1px solid #FFFFFF;text-align:center;" align="center"><span style="font-size:10px;color:#000000;line-height:200%;font-family:verdana;text-decoration:none;">Email not displaying correctly? <a href="*|ARCHIVE|*" style="font-size:10px;color:#ff7700;line-height:200%;font-family:verdana;text-decoration:none;">View it in your browser.</a></span></td>
  34. </tr>
  35. <tr>
  36. <td align="left" valign="middle" style="background-color:#505050;border-top:0px solid #333333;border-bottom:10px solid #FFFFFF;"><center><a href=""><IMG id=editableImg1 SRC="" BORDER="0" title="" alt="" align="center"></a></center></td>
  37. </tr>
  38. </table>
  39. <table width="600" cellpadding="20" cellspacing="0" bgcolor="#FFFFFF">
  40. <tr>
  41. <td width="200" valign="top" style="background-color:#FFFFFF;border-right:1px solid #CCCCCC;text-align:left;">
  42. <span style="font-size:11px;font-weight:normal;color:#505050;font-family:arial;line-height:150%;">
  43. <p>
  44. Attention: ' . $name . ',
  45. </p>
  46. <center><a href=""><IMG id=editableImg1 SRC="" BORDER="0" title="" alt="" align="center"></a></center>
  47. <br>
  48. <span style="font-size:15px;font-weight:bold;color:#333333;font-family:arial;line-height:150%;"></span><br>
  49. <br>
  50. <span style="font-size:15px;font-weight:bold;color:#333333;font-family:arial;line-height:150%;"></span><br>
  51. <br>
  52. <center><a href=""><IMG id=editableImg1 SRC="" BORDER="0" title="" alt="" align="center"></a></center>
  53. </span>
  54. </td>
  55. <td bgcolor="#FFFFFF" valign="top" width="400" style="font-size:12px;color:#000000;line-height:150%;font-family:trebuchet ms;"
  56. <p>
  57. <span style="font-size:20px;font-weight:bold;color:#ff7700;font-family:arial;line-height:110%;"></span><br>
  58. <br>
  59. <center><a href=""><IMG id=editableImg1 SRC="" BORDER="0" title="" alt="" align="right"></a></center>
  60. </p>
  61. <p>
  62. <a href="" title=""></a><br><br>
  63. <br><br>
  64. <span style="font-size:15px;font-weight:bold;color:#000000;font-family:arial;line-height:110%;"></span><br>
  65. <br>
  66. <a href="" title=""></a>
  67. </p>
  68. </td>
  69. </tr>
  70. <tr>
  71. <td style="background-color:#505050;border-top:10px solid #FFFFFF;" valign="top" colspan="2">
  72. <span style="font-size:10px;color:#ffffff;line-height:100%;font-family:verdana;">
  73. Trilithon Newsletter <br />
  74. <br />
  75. <a href="" title="Unsubscribe from Newsletter">Unsubscribe</a> *|EMAIL|* from this list.<br />
  76. <br />
  77. Our mailing address is:<br />
  78. <a href="" title=""></a><br />
  79. <br />
  80. Our telephone:<br />
  81. <br />
  82. <br />
  83. Copyright (C) 2007 All rights reserved.<br />
  84. <br />
  85. <a href="*|FORWARD|*" title="Forward to a friend">Forward</a> this email to a friend
  86. </span>
  87. </td>
  88. </tr>
  89. </table>
  90. </td>
  91. </tr>
  92. </table>
  93. </body>
  94. </html>
  95. ';
  96. $subject = "";
  97. $headers = "From:\r\n";
  98. $headers .= "Content-type: text/html\r\n";
  99. $to = "$email";
  100.  
  101. $mail_result = mail($to, $subject, $mail_body, $headers);
  102.  
  103. if ($mail_result) {
  104. mysql_query("UPDATE mail SET field_9='1' WHERE field_4='$email' LIMIT 1");
  105. } else {
  106. // this else statement can be used to write into an error log if the mail function fails
  107. // It can also be removed if you do not need error logging
  108. }
  109.  
  110. }
  111. ?>
  112. <?php
  113. // This section is script I discussed adding to this file on video
  114. // This section is for sending the site owner a message informing them that
  115. // all people in the database have been sent the newsletter for the current campaign
  116. if ($numRows == 0) { // $numRows is set on line 4 using the existing query
  117.  
  118. $subj = "Newsletter Campaign Has Ended";
  119. $body = "The current newsletter campaign has ended. All have been sent the newsletter.";
  120. $hdr = "From:\r\n";
  121. $hdr .= "Content-type: text/html\r\n";
  122. mail("", $subj, $body, $hdr);
  123.  
  124. }
  125. // End Check Section
  126. ?>
  127.  

If someone can help me I would really appreciate it.
Similar Threads
Reputation Points: 10
Solved Threads: 4
Light Poster
trilithon is offline Offline
38 posts
since Jun 2010
Jun 19th, 2010
0
Re: PHP Parse error
You need to remove any single quotes within the string or escape them with a backslash.
Sponsor
Featured Poster
Reputation Points: 531
Solved Threads: 711
Bite my shiny metal ass!
pritaeas is offline Offline
4,125 posts
since Jul 2006
Jun 25th, 2010
0
Re: PHP Parse error
here i fixed it, i escape all the single qoutes(') in your $mail_body string

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. include_once "connect_to_mysql.php";
  3. $sql = mysql_query("SELECT * FROM mail WHERE field_9='0' AND field_8='max' LIMIT 20");
  4. $numRows = mysql_num_rows($sql); // Added for "End Campaign Check" at the bottom of this file(not shown on the video)
  5. $mail_body = '';
  6. while($row = mysql_fetch_array($sql)){
  7. $id = $row["id"];
  8. $email = $row["field_4"];
  9. $name = $row["field_5"];
  10.  
  11. $mail_body = '
  12. <html>
  13. <body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0" bgcolor=\'#505050\' >
  14. <STYLE>
  15. .headerTop { background-color:#ffffff; border-top:0px solid #000000; border-bottom:1px solid #FFFFFF; text-align:center; }
  16. .adminText { font-size:10px; color:#ff7700; line-height:200%; font-family:verdana; text-decoration:none; }
  17. .headerBar { background-color:#e0e0e0; border-top:0px solid #333333; border-bottom:10px solid #FFFFFF; }
  18. .title { font-size:20px; font-weight:bold; color:#ff7700; font-family:arial; line-height:110%; }
  19. .subTitle { font-size:11px; font-weight:normal; color:#666666; font-style:italic; font-family:arial; }
  20. td { font-size:12px; color:#000000; line-height:150%; font-family:trebuchet ms; }
  21. .sideColumn { background-color:#e0e0e0; border-right:1px solid #505050; text-align:left; }
  22. .sideColumnText { font-size:11px; font-weight:normal; color:#999999; font-family:arial; line-height:150%; }
  23. .sideColumnTitle { font-size:15px; font-weight:bold; color:#333333; font-family:arial; line-height:150%; }
  24. .footerRow { background-color:#505050; border-top:10px solid #FFFFFF; }
  25. .footerText { font-size:10px; color:#ffffff; line-height:100%; font-family:verdana; }
  26. a { color:#FF6600; color:#FF6600; color:#FF6600; }
  27. </STYLE>
  28. <table width="100%" cellpadding="10" cellspacing="0" bgcolor=\'#505050\' >
  29. <tr>
  30. <td valign="top" align="center">
  31. <table width="600" cellpadding="0" cellspacing="0">
  32. <tr>
  33. <td style="background-color:#ffffff;border-top:0px solid #000000;border-bottom:1px solid #FFFFFF;text-align:center;" align="center"><span style="font-size:10px;color:#000000;line-height:200%;font-family:verdana;text-decoration:none;">Email not displaying correctly? <a href="*|ARCHIVE|*" style="font-size:10px;color:#ff7700;line-height:200%;font-family:verdana;text-decoration:none;">View it in your browser.</a></span></td>
  34. </tr>
  35. <tr>
  36. <td align="left" valign="middle" style="background-color:#505050;border-top:0px solid #333333;border-bottom:10px solid #FFFFFF;"><center><a href=""><IMG id=editableImg1 SRC="" BORDER="0" title="" alt="" align="center"></a></center></td>
  37. </tr>
  38. </table>
  39. <table width="600" cellpadding="20" cellspacing="0" bgcolor="#FFFFFF">
  40. <tr>
  41. <td width="200" valign="top" style="background-color:#FFFFFF;border-right:1px solid #CCCCCC;text-align:left;">
  42. <span style="font-size:11px;font-weight:normal;color:#505050;font-family:arial;line-height:150%;">
  43. <p>
  44. Attention: \' . $name . \',
  45. </p>
  46. <center><a href=""><IMG id=editableImg1 SRC="" BORDER="0" title="" alt="" align="center"></a></center>
  47. <br>
  48. <span style="font-size:15px;font-weight:bold;color:#333333;font-family:arial;line-height:150%;"></span><br>
  49. <br>
  50. <span style="font-size:15px;font-weight:bold;color:#333333;font-family:arial;line-height:150%;"></span><br>
  51. <br>
  52. <center><a href=""><IMG id=editableImg1 SRC="" BORDER="0" title="" alt="" align="center"></a></center>
  53. </span>
  54. </td>
  55. <td bgcolor="#FFFFFF" valign="top" width="400" style="font-size:12px;color:#000000;line-height:150%;font-family:trebuchet ms;"
  56. <p>
  57. <span style="font-size:20px;font-weight:bold;color:#ff7700;font-family:arial;line-height:110%;"></span><br>
  58. <br>
  59. <center><a href=""><IMG id=editableImg1 SRC="" BORDER="0" title="" alt="" align="right"></a></center>
  60. </p>
  61. <p>
  62. <a href="" title=""></a><br><br>
  63. <br><br>
  64. <span style="font-size:15px;font-weight:bold;color:#000000;font-family:arial;line-height:110%;"></span><br>
  65. <br>
  66. <a href="" title=""></a>
  67. </p>
  68. </td>
  69. </tr>
  70. <tr>
  71. <td style="background-color:#505050;border-top:10px solid #FFFFFF;" valign="top" colspan="2">
  72. <span style="font-size:10px;color:#ffffff;line-height:100%;font-family:verdana;">
  73. Trilithon Newsletter <br />
  74. <br />
  75. <a href="" title="Unsubscribe from Newsletter">Unsubscribe</a> *|EMAIL|* from this list.<br />
  76. <br />
  77. Our mailing address is:<br />
  78. <a href="" title=""></a><br />
  79. <br />
  80. Our telephone:<br />
  81. <br />
  82. <br />
  83. Copyright (C) 2007 All rights reserved.<br />
  84. <br />
  85. <a href="*|FORWARD|*" title="Forward to a friend">Forward</a> this email to a friend
  86. </span>
  87. </td>
  88. </tr>
  89. </table>
  90. </td>
  91. </tr>
  92. </table>
  93. </body>
  94. </html>
  95. ';
  96. $subject = "";
  97. $headers = "From:\r\n";
  98. $headers .= "Content-type: text/html\r\n";
  99. $to = "$email";
  100.  
  101. $mail_result = mail($to, $subject, $mail_body, $headers);
  102.  
  103. if ($mail_result) {
  104. mysql_query("UPDATE mail SET field_9='1' WHERE field_4='$email' LIMIT 1");
  105. } else {
  106. // this else statement can be used to write into an error log if the mail function fails
  107. // It can also be removed if you do not need error logging
  108. }
  109.  
  110. }
  111. ?>
  112. <?php
  113. // This section is script I discussed adding to this file on video
  114. // This section is for sending the site owner a message informing them that
  115. // all people in the database have been sent the newsletter for the current campaign
  116. if ($numRows == 0) { // $numRows is set on line 4 using the existing query
  117.  
  118. $subj = "Newsletter Campaign Has Ended";
  119. $body = "The current newsletter campaign has ended. All have been sent the newsletter.";
  120. $hdr = "From:\r\n";
  121. $hdr .= "Content-type: text/html\r\n";
  122. mail("", $subj, $body, $hdr);
  123.  
  124. }
  125. // End Check Section
  126. ?>
Reputation Points: 32
Solved Threads: 55
Posting Pro in Training
vaultdweller123 is offline Offline
448 posts
since Sep 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: how to write validation for multiple roles?
Next Thread in PHP Forum Timeline: Turn off 500 Error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC