0

I have been doing this registration project in php, however whenever i access it on localhost (im using wampserver), its giving me this error

  1. On home page of sign up (top view): ERROR: Notice: Undefined index: fname in enter image description here

  2. On home page of sign up (buttom view) ERROR: Notice: Undefined variable: feedback in enter image description here

  3. upon sending an email(which doesn't proceed due to error) ERROR: Warning: 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 enter image description here


I am not really sure what when wrong since this is the first time i tried coding a php file that sends an email. I hope someone can help me out here

---here is the code i used(i based it on tutorials i see)

<?php

$to = "temblormariel@ymail.com";
$subject = 'SmoothTeamPH SignUp Registration';

$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$pnum = $_POST['pnum'];
$shippingAdd = $_POST['shippingAdd'];

$body = <<<Email

Hi!

Smooth Team PH New Registration

First Name: $fname
Last Name: $lname
Email Address: $email
Phone Number: $pnum
Shipping Address: $shippingAdd

Thanks,
$lname, $fname

Email;

$header = "From: $email";

if($_POST){
    if($lname == '' || $fname == '' || $email == '' || $pnum == '' || $shippingAdd == ''){
        $feedback = 'Kindly fill out all the fields';
    }else{
        mail($to, $subject, $body, $header);
        $feedback = "Thank you for providing your information. We will get back to you shortly";
    }

}
?>


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Smooth Team PH Inc</title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<div id="container">
    <header id="header">
        <div id="menu" class="menu">
            <ul>
                <li><a href="#" target="_blank"> HOME </a></li>
                <li><a href="#" target="_blank"> SIGN UP </a></li>
                <li><a href="#" target="_blank"> ABOUT US </a></li>
                <li><a href="#" target="_blank"> CONTACT </a></li>
            </ul> 
        </div>
</header>


<section id="content">
    <h2>Sign Up</h2>
            <div id="signup">
            <form action="?" method="post">

                <ul>
                    <li>
                        <label for="fname">First Name : </label>
                        <input type="text" name="fname" id="fname" />
                    </li>
                    <li>
                        <label for="lname">Last Name : </label>
                        <input type="text" name="lname" id="lname" />
                    </li>
                    <li>
                        <label for="email">Email : </label>
                        <input type="text" name="email" id="email" />
                    </li>
                    <li>
                        <label for="pnum"> Phone Number : </label>
                        <input type="text" name="pnum" id="pnum" />
                    </li>
                    <li>
                         <label for="shippingAdd">Shipping Address : </label>
                         <textarea id="shippingAdd" name="shippingAdd" cols="42" rows="9"></textarea>
                    </li>
                    <li>
                        <input type="submit" value="Submit">
                    </li>
                </ul>

                <p id="feedback"> <?php echo $feedback; ?> </p> <!-- will be transfered to 2nd page later -->
            </form>
            </div>
</section>


<footer id="footer">
    <div id="fmenu" class="fmenu">
        <p>©2015 smoothteamphinc    |   Design & Development by Mariel Temblor</p>
</footer>
    </div>
</div>
</body>
</html>
MisaChan
  • 279
  • 5
  • 15
  • You need to configure a SMTP server in `php.ini` on your local server in order to send emails. – ojovirtual Sep 11 '15 at 11:04
  • You forgot `$feedback = $_POST['feedback'];` you should read about XSS injection and input validation and input sanitizing, code does not look safe to me. – Daniel W. Sep 11 '15 at 11:06
  • @ojovirtual, how do i do that? – MisaChan Sep 11 '15 at 11:36
  • @DanFromGermany, i tried doing something like that, i added $feedback = ''; above $header = "From: $email" and it worked out fine – MisaChan Sep 11 '15 at 11:37
  • i managed to fix error 1 and 2, and will post how later, just the 3rd error thats giving me headache. i dont know what to put in smtp – MisaChan Sep 11 '15 at 11:48
  • In order to send emails you need a server or at least an email account. I'll recommend using `PHPMailer` instead of the mail function. You have a lot of information here http://stackoverflow.com/questions/14456673/sending-email-with-php-from-an-smtp-server/14456761#14456761 – ojovirtual Sep 11 '15 at 12:01

1 Answers1

0

for my qyestions, here is what I did

Error 1: instead of doing

$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$pnum = $_POST['pnum'];
$shippingAdd = $_POST['shippingAdd'];

I did

$fname = isset($_POST['fname']) ? $_POST['fname'] : '';
$lname = isset($_POST['lname']) ? $_POST['lname'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$pnum = isset($_POST['pnum']) ? $_POST['pnum'] : '';
$shippingAdd = isset($_POST['shippingAdd']) ? $_POST['shippingAdd'] : '';

Error 2: I added another variable declaration outside the if statemate. and added it above the $header declaration. and assigned an empty value in it.

$feedback = "";
$header = "From: $email";

Error 3:

We really couldn't figure out the best way to solve this since it is email, and i really have no idea what to put on the smtp, so my friend let me borrow for a sec his domain so that i could at least check if the code is working. and yes, it does. I have received the email on my $to code.

i hope this could be of some help to others who experience the same thing. special thanks to my friend :)

MisaChan
  • 279
  • 5
  • 15