O'Reilly Forums: Chapter 1 Code Erros - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Chapter 1 Code Erros

#1 User is offline   dannie_manji 

  • New Member
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 01-February 12

Posted 11 February 2012 - 10:26 AM

guys, am having problems with codes for chapter 1. i'm getting these two errors:
1. Notice: Undefined index: fangspotted in C:\wamp\www\headfirst\ch01\final\aliens\report.php on line 19
2. Warning: mail() [function.mail]: Failed to connect to mailserver at "smtp.localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\headfirst\ch01\final\aliens\report.php on line 31

i'm using wampserver 2.2c for 64-bit, please help me fix them!
0

#2 User is offline   drewdin 

  • Veteran Member
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 494
  • Joined: 11-February 10
  • Gender:Male
  • Location:Boston

Posted 12 February 2012 - 01:04 PM

View Postdannie_manji, on 11 February 2012 - 10:26 AM, said:

guys, am having problems with codes for chapter 1. i'm getting these two errors:
1. Notice: Undefined index: fangspotted in C:\wamp\www\headfirst\ch01\final\aliens\report.php on line 19
2. Warning: mail() [function.mail]: Failed to connect to mailserver at "smtp.localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\headfirst\ch01\final\aliens\report.php on line 31

i'm using wampserver 2.2c for 64-bit, please help me fix them!



Post your code so we can inspect it
0

#3 User is offline   dannie_manji 

  • New Member
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 01-February 12

Posted 13 March 2012 - 07:26 PM

View Postdrewdin, on 12 February 2012 - 01:04 PM, said:

Post your code so we can inspect it

here are the codes

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Aliens Abducted Me - Report an Abduction</title>
</head>
<body>
<h2>Aliens Abducted Me - Report an Abduction</h2>

<?php

$name = $_POST['firstname'] . ' ' . $_POST['lastname'];
$when_it_happened = $_POST['whenithappened'];
$how_long = $_POST['howlong'];
$how_many = $_POST['howmany'];
$alien_description = $_POST['aliendescription'];
$what_they_did = $_POST['whattheydid'];
$fang_spotted = $_POST['fangspotted'];
$email = $_POST['email'];
$other = $_POST['other'];

$to = 'owen@aliensabductedme.com';
$subject = 'Aliens Abducted Me - Abduction Report';
$msg = "$name was abducted $when_it_happened and was gone for $how_long.\n" .
"Number of aliens: $how_many\n" .
"Alien description: $alien_description\n" .
"What they did: $what_they_did\n" .
"Fang spotted: $fang_spotted\n" .
"Other comments: $other";
mail($to, $subject, $msg, 'From:' . $email);

echo 'Thanks for submitting the form.<br />';
echo 'You were abducted ' . $when_it_happened;
echo ' and were gone for ' . $how_long . '<br />';
echo 'Number of aliens: ' . $how_many . '<br />';
echo 'Describe them: ' . $alien_description . '<br />';
echo 'The aliens did this: ' . $what_they_did . '<br />';
echo 'Was Fang there? ' . $fang_spotted . '<br />';
echo 'Other comments: ' . $other . '<br />';
echo 'Your email address is ' . $email;
?>

</body>
</html>
0

#4 User is offline   drewdin 

  • Veteran Member
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 494
  • Joined: 11-February 10
  • Gender:Male
  • Location:Boston

Posted 14 March 2012 - 12:28 PM

you wont be able to send an email from your local computer, the easiest way to send emails using php is to get a hosting company like gocrappy, 171 etc...

So it looks like your code is being executed before being posted so your getting errors about the undefined index. I cant remember but you should have an

if(isset($_POST['submit']))


somewhere in there. I'll have to check the errata or verify your code vs. the downloaded examples.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users