Jump to content

prasadwalvekar

New Members
  • Posts

    2
  • Joined

  • Last visited

prasadwalvekar's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you all. Solved the problem using if(isset($subject)) { echo $subject; } if(isset($text)) { echo $text; }
  2. Hi all, I browsed through various forums looking for a solution to the problem i am facing. i came upon a few similar problems others were facing but solution to their code does not seem to work with my code. i'll be grateful if someone could please point me in the right direction. This is the notice that my browser shows me- Notice: Undefined variable: subject in C:\wamp\www\.....\sendemail4.php on line 69 Call Stack #TimeMemoryFunctionLocation 10.0010247784{main}( )..\sendemail4.php:0 "> Also, please find attached a screenshot of what i am getting after running the php script in my localhost. Here's the code from Head First php mysql book chapter 4 that i am trying to run- <html> <head> <title> Make Me Elvis - Send Email </title> </head> <body> <p><strong>Private:</strong> For Elmer's use only <br /> Write and send an email to mailing list numbers.</p> <?php //Detecting form submission using isset() function //Making forms sticky if (!empty($_POST['submit'])) { $from = 'prasadwalvekar@yahoo.com'; $subject = $_POST['subject']; $text = $_POST['elvismail']; $output_form = false; if( empty($subject) && empty($text) ) { //Both $subject and $text are blank echo 'You forgot the email subject and body text'; $output_form = true; } if( empty($subject) && !empty($text) ) { //$subject is empty and $text is not empty echo 'You forgot email subject.'; $output_form = true; } if( !empty($subject) && empty($text) ) { //$subject is not empty and $text is empty echo 'You forgot email body text.'; $output_form = true; } } else { $output_form = true; //if form's never been submitted, show it! } if((!empty($subject)) && (!empty($text))) { $dbc = mysqli_connect('localhost', 'root', '', 'elvis_store') or die('Error connecting to MySQL server.'); $query = "SELECT * FROM email_list"; $result = mysqli_query($dbc, $query) or die('Error querying database'); while ($row = mysqli_fetch_array($result)) { $to = $row['email']; $first_name = $row['first_name']; $last_name = $row['last_name']; $msg = "Dear $first_name $last_name, \n $text"; mail($to, $subject, $msg, 'From:' . $from); echo 'Email sent to: ' . $to . '<br />'; } mysqli_close($dbc); } if ($output_form) { ?> <form method="post" action="<? php echo $_SERVER['PHP_SELF']; ?>"> Subject of email: <input type="text" name="subject" value=" <?php echo $subject; ?> "><br /> Body of email: <textarea name = "elvismail" rows="8" cols="40"><?php echo $text; ?></textarea><br /> <br /> <input type = "submit" name = "submit" /> </form> <?php } ?> </body> </html>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.