twilitegxa Posted July 7, 2009 Share Posted July 7, 2009 I am writing code to send my newsletter out to a mailing list saved in the database, but I am receiving this error: Parse error: parse error in C:\wamp\www\sendmymail.php on line 32 Here is the code: <?php if ($_POST['op'] != "send") { //haven't seen the form, so show it print " <html> <head> <title>Send A Newsletter</title> </head> <body> <h1>Send A Newsletter</h1> <form method=\"post\" action=\"$_SERVER[php_SELF]\"> <p><strong>Subject:</strong><br> <input type=\"text\" name=\"subject\" size=30></p> <p><strong>Mail Body:</strong><br> <textarea name=\"message\" cols=50 rows=10 wrap=virtual></textarea> <input type=\"hidden\" name=\"op\" value=\"send\"></p> <p><input type=\"submit\" name=\"submit\" value=\"Send It\"></p> </form> </body> </html>"; } else if ($_POST['op'] == "send") { //want to send form, so check for required fields if (($_POST['subject'] =="") || ($_POST['message'] == "")) { header("Location: sendmymail.php"); exit; } //connect to database $conn = msql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("smrpg"$conn) or die(mysql_error()); //get emails from subscribers list $sql = "select email from subscribers"; $result = mysql_query($sql,$conn) or die(mysql_error()); //create a From: mailheader $headers = "From: Your Mailing List <[email protected]>\n"; //loop through results and send mail while ($row = mysql_fetch_array($result)) { set-time_limit(0); $email = $row['email']; mail("$email", stripslashes($_POST['subject']), stripslashes($_POST['message']), $headers); print "newsletter sent to: $email<br>"; } } ?> What am I missing? Can anyone see it? Link to comment https://forums.phpfreaks.com/topic/165029-solved-send-mail-form/ Share on other sites More sharing options...
AwptiK Posted July 7, 2009 Share Posted July 7, 2009 mysql_select_db("smrpg"$conn) or die(mysql_error()); should be mysql_select_db("smrpg",$conn) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/165029-solved-send-mail-form/#findComment-870238 Share on other sites More sharing options...
twilitegxa Posted July 7, 2009 Author Share Posted July 7, 2009 Thank you so much! Don't know how I missed that! Now I am receiving this error: Notice: Undefined index: op in C:\wamp\www\sendmymail.php on line 2 How do I fix this error? Link to comment https://forums.phpfreaks.com/topic/165029-solved-send-mail-form/#findComment-870239 Share on other sites More sharing options...
AwptiK Posted July 7, 2009 Share Posted July 7, 2009 That's because 'op' isn't defined yet. You should use if(!isset($_POST['op'])) { //display form } Edit: Just so you know, isset checks to see if it has a value, any value, so !isset means it has no value, or hasn't been set. Link to comment https://forums.phpfreaks.com/topic/165029-solved-send-mail-form/#findComment-870240 Share on other sites More sharing options...
twilitegxa Posted July 7, 2009 Author Share Posted July 7, 2009 Thank you so much! That fixed the problem! Link to comment https://forums.phpfreaks.com/topic/165029-solved-send-mail-form/#findComment-870243 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.