So now my son is into PHP and so I bought a book for him, Head First PHP and MySQL and my son took the code and tried it. The main page is report.html.

report.html:-

<!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>



  <p>Share your story of alien abduction:</p>

  <form method="post" action="report.php">

    <label for="firstname">First name:</label>

    <input type="text" id="firstname" name="firstname" /><br />

    <label for="lastname">Last name:</label>

    <input type="text" id="lastname" name="lastname" /><br />

    <label for="email">What is your email address?</label>

    <input type="text" id="email" name="email" /><br />

    <label for="whenithappened">When did it happen?</label>

    <input type="text" id="whenithappened" name="whenithappened" /><br />

    <label for="howlong">How long were you gone?</label>

    <input type="text" id="howlong" name="howlong" /><br />

    <label for="howmany">How many did you see?</label>

    <input type="text" id="howmany" name="howmany" /><br />

    <label for="aliendescription">Describe them:</label>

    <input type="text" id="aliendescription" name="aliendescription" size="32" /><br />

    <label for="whattheydid">What did they do to you?</label>

    <input type="text" id="whattheydid" name="whattheydid" size="32" /><br />

    <label for="fangspotted">Have you seen my dog Fang?</label>

    Yes <input id="fangspotted" name="fangspotted" type="radio" value="yes" />

    No <input id="fangspotted" name="fangspotted" type="radio" value="no" /><br />



    <label for="other">Anything else you want to add?</label>

    <textarea id="other" name="other"></textarea><br />

    <input type="submit" value="Report Abduction" name="submit" />

  </form>

</body>

</html>

report.php:-

<!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 = 'cadencerayn@yahoo.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>

And when he tries the page, all those echo statements take place, but above the statements, is this error message:-

( ! ) Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\report.php on line 30
Call Stack
#   Time    Memory  Function    Location
1   0.1019  379384  {main}( )   ..\report.php:0
2   0.1020  380536  mail ( )    ..\report.php:30

Tell me if you want my php.ini. I didn't include it here because it is awfully long.

How to solve the error? I also did not get any email.

P.S. I use WampServer.

Recommended Answers

All 11 Replies

Member Avatar for diafol

I'm assuming you don't have a mailserver running. In order to make use of email, you will need this. If using XAMPP, turn on Mercury Mail and read the manual.

I didn't understand what you said. I have no idea what a mailserver is, nor do I know what "XAMPP" or Mercury Mail is. He knows only HTML in the web development category (He usually programs in the software development category). So please explain everything in easier words. When I bought(rebooted) my computer, it came with PHP and MySQL. I downloaded WampServer and I began.

Line 30 of report.php is trying to send out email. Apache is a web server which can serve PHP pages. MySQL is a database server which manages the database. You need a mail server in order to send out email.

How to get this mailserver? My son doesn't even know whether he has Apache or not. He does all the testing on WampServer.

if you have smtp, then configure your php.ini with it. Other than that, here is a good link to learn from click

No idea what smtp is. As I said, he doesn't know anything about web development(other than HTML).

Member Avatar for diafol

The Simple Mail Transfer Protocol (SMTP) is just a way of sending information across IP networks (email in simple terms). Mail servers use SMTP. You need to know which servers you have installed on your machine. php can run on a number of different ones under Windows, IIS or Apache, however this will not allow you to send email from your own PC. For this you need a mailserver. Wampserver uses Apache, but does not include a mailserver (like Mercury Mail). So, until you download a mailserver, no email can be sent from your machine.

http://www.pmail.com/downloads_s3_t.htm

The link has Pegasus Mail or Mercury Mail (I've only ever used Mercury, so can't comment on Pegasus).

So how do I get a mailserver? And how do I install it? And one more thing, WampServer is just for testing. How do I get a mailserver on the real Internet server I will be hosting on?(000webhost) I just heard that these spammer spybots can get your email id and use it for bad purposes. How to prevent that from happening?

Member Avatar for diafol

So how do I get a mailserver? And how do I install it? And one more thing, WampServer is just for testing. How do I get a mailserver on the real Internet server I will be hosting on?(000webhost)

I supplied the link. You download and install it. There should be instructions with it. As for mailserver with your host, it depends on your plan. You may already have an account for the mailserver. Read the blurb for the web account. Some of the cheapest accounts may not have one, but they are few and far between. You should see a 'webmail account' in your hosting control panel.

EDIT

A quick look at 000 shows that you have webmail, but no SMTP for a free account. A paid account (about $5/month) supplies an SMTP server.

I just heard that these spammer spybots can get your email id and use it for wrong purposes. How to prevent that from happening?

Member Avatar for diafol

This is a different question. Not php related. Have a Google on spoofed emails.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.