Jump to content

certain things isnt working


divinedesigns1

Recommended Posts

hey sup?i am having problem with sending emails to the people who subscribe to receive the newsletter, it send the email but it doesnt show the errors anymore nor does it keep the info into the fields, also even if the fields are empty it still send the email out. this is the site www.divinedesigns1.com/demo/blast.php and this is the code

<?phpif(isset($_POST['submit'])){  $from = 'ty@ty.net';  $subject = $_POST['subject'];  $text = $_POST['divineblast'];  $display_form = false;if(empty($subject) && empty($text)){  //We know both $subject AND $text are blank  echo 'Fill in both body and subject.<br/>';  $display_form = true;}if(empty($subject) && (!empty($text))){  echo 'you forgot the email subject.<br/>';  $display_form = true;}if((!empty($subject)) && empty($text)){  echo 'you forgot the body text.<br/>';  $display_form = true;}if((!empty($subject)) && (!empty($text))){  //Send the email}}else{$display_form = true;}if($display_form){  ?><table border="0" align="center" width="405"><tr><td width="399"><form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">    <label for="subject">Subject of email:</label><br />    <input id="subject" name="subject" type="text" size="30" value="<?php echo $subject; ?>"/><br />    <label for="divineblast">Body of email:</label><br />    <textarea id="divineblast" name="divineblast" rows="8" cols="40"><?php echo $text; ?></textarea><br />    <input type="submit" name="Submit" id="submit" value="Submit" />  </form></td></tr></table><?php  }  $dbc = mysqli_connect(ty, ty, ty', 'ty')    or die('Error connecting to MySQL server.');  $query = "SELECT * FROM newsletter";  $result = mysqli_query($dbc, $query)    or die('Error querying database.');  while ($row = mysqli_fetch_array($result)){    $to = $row['email'];    $first_name = $row['fname'];    $last_name = $row['lname'];    $msg = "Dear $firstname $lastname,\n$text";    mail($to, $subject, $msg, 'From:' . $from);    echo 'Email sent to: ' . $to . '<br />';  }  mysqli_close($dbc);?>

what am i doing wrong?

Link to comment
Share on other sites

I don't really see anything that would prevent the email from being sent in the first place. In other words, I don't see any conditionals that would allow for the email to be sent or not. The code is just there at the end of the script. As for the error messages and output, what have you tried to debug the situation? Are you adding output to check the values of $_POST, $subject, and $text to make sure they are what you expect them to be as the conditionals work through their cases? Also, I don't know if it's a posting error, but you're mysqli_connect statement looks odd, with the quotes the way they are.

Link to comment
Share on other sites

I don't really see anything that would prevent the email from being sent in the first place. In other words, I don't see any conditionals that would allow for the email to be sent or not. The code is just there at the end of the script. As for the error messages and output, what have you tried to debug the situation? Are you adding output to check the values of $_POST, $subject, and $text to make sure they are what you expect them to be as the conditionals work through their cases? Also, I don't know if it's a posting error, but you're mysqli_connect statement looks odd, with the quotes the way they are.
yea i put the quotes like that, since i deleted the orginal infor for the mysqli_connect statement and yes i have check the value of each post
Link to comment
Share on other sites

From the looks of it, it's still send the email regardless because if you look at this part(see comments):

if($display_form){  // If this is true, it means any of the form fields are empty; this should display FIRST when a user comes to the page to begin with.  ?><table border="0" align="center" width="405"><tr><td width="399"><form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">	<label for="subject">Subject of email:</label><br />	<input id="subject" name="subject" type="text" size="30" value="<?php echo $subject; ?>"/><br />	<label for="divineblast">Body of email:</label><br />	<textarea id="divineblast" name="divineblast" rows="8" cols="40"><?php echo $text; ?></textarea><br />	<input type="submit" name="Submit" id="submit" value="Submit" />  </form></td></tr></table><?php  } // This is the end of the IF statement. After this, everything below will run thus sending the email regardless if the form fields are empty or not  $dbc = mysqli_connect(ty, ty, ty', 'ty')	or die('Error connecting to MySQL server.');  $query = "SELECT * FROM newsletter";  $result = mysqli_query($dbc, $query)	or die('Error querying database.');  while ($row = mysqli_fetch_array($result)){	$to = $row['email'];	$first_name = $row['fname'];	$last_name = $row['lname'];	$msg = "Dear $firstname $lastname,\n$text";	mail($to, $subject, $msg, 'From:' . $from);	echo 'Email sent to: ' . $to . '<br />';  }  mysqli_close($dbc);?>

What you have to do from the looks of it is ONLY send the email when ALL the form fields are not empty(!empty()).

Link to comment
Share on other sites

From the looks of it, it's still send the email regardless because if you look at this part(see comments):
if($display_form){  // If this is true, it means any of the form fields are empty; this should display FIRST when a user comes to the page to begin with.  ?><table border="0" align="center" width="405"><tr><td width="399"><form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">	<label for="subject">Subject of email:</label><br />	<input id="subject" name="subject" type="text" size="30" value="<?php echo $subject; ?>"/><br />	<label for="divineblast">Body of email:</label><br />	<textarea id="divineblast" name="divineblast" rows="8" cols="40"><?php echo $text; ?></textarea><br />	<input type="submit" name="Submit" id="submit" value="Submit" />  </form></td></tr></table><?php  } // This is the end of the IF statement. After this, everything below will run thus sending the email regardless if the form fields are empty or not  $dbc = mysqli_connect(ty, ty, ty', 'ty')	or die('Error connecting to MySQL server.');  $query = "SELECT * FROM newsletter";  $result = mysqli_query($dbc, $query)	or die('Error querying database.');  while ($row = mysqli_fetch_array($result)){	$to = $row['email'];	$first_name = $row['fname'];	$last_name = $row['lname'];	$msg = "Dear $firstname $lastname,\n$text";	mail($to, $subject, $msg, 'From:' . $from);	echo 'Email sent to: ' . $to . '<br />';  }  mysqli_close($dbc);?>

What you have to do from the looks of it is ONLY send the email when ALL the form fields are not empty(!empty()).

yea, i had 2 parts of the codes mixed up so then outputting the errors and not sending the email it sends the email without outputting the errors lol i got it fix tho
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...