Hello,
I’m trying to make my contact form to work. Every time I send the information I get an undefined name for my parameters.
See code below.
<?php
$errorMSG = "";
// NAME
if (empty($_POST["name"])) {
$errorMSG = "Name is required";
} else {
$name = $_POST["name"];
}
// EMAIL
if (empty($_POST["email"])) {
$errorMSG .= "Email is required ";
} else {
$email = $_POST["email"];
}
// MESSAGE
if (empty($_POST["message"])) {
$errorMSG .= "Message is required";
} else {
$message = $_POST["message"];
}
$EmailTo = "info@renovas.co";
$Subject = "New Message Received From Client";
$Name = $_POST['name'];
$Email = $_POST['email'];
$Message = $_POST['message'];
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From:".$email);
// redirect to success page
if ($success && $errorMSG == ""){
echo "success";
}else{
if($errorMSG == ""){
echo "Something went wrong :(";
} else {
echo $errorMSG;
}
}
?>
donboe
July 23, 2018, 9:24pm
2
Do you have a working example? Can you post the html (the form) as well? Which parameters.are you refering to? etc etc. It is very hard to say since you only show us the PHP. Please be more detailed
Consistency can be a good thing. Inside the if conditionals either an error message is being assigned values, - or - lowercase variables are assigned values.
Later the same variable names, but with the first letter uppercase are assigned values.
Then the lowercase variables, that may or may not have been assigned values depending on the if conditionals are used in $Body
1 Like
Thanks donboe!
Heres is the HTML
RENOVAS - Home Solutions
<!-- ==============================================
Favicons
=============================================== -->
<link rel="shortcut icon" href="images/favicon.ico">
<link rel="apple-touch-icon" href="images/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png">
<!-- ==============================================
CSS VENDOR
=============================================== -->
<link rel="stylesheet" type="text/css" href="css/vendor/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="css/vendor/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="css/vendor/owl.carousel.min.css">
<link rel="stylesheet" type="text/css" href="css/vendor/owl.theme.default.min.css">
<link rel="stylesheet" type="text/css" href="css/vendor/magnific-popup.css">
<!-- ==============================================
Custom Stylesheet
=============================================== -->
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script type="text/javascript" src="js/vendor/modernizr.min.js"></script>
<!-- Load page -->
<div class="animationload">
<div class="loader"></div>
</div>
<!-- BACK TO TOP SECTION -->
<a href="#0" class="cd-top cd-is-visible cd-fade-out">Top</a>
<!-- HEADER -->
<div class="header header-1">
<!-- TOPBAR -->
<div class="topbar">
<div class="container">
<div class="row">
<div class="col-sm-5 col-md-6">
<div class="topbar-left">
<div class="welcome-text">
Diversified Services. Unvarying Quality. Competitive Costs
</div>
</div>
</div>
<div class="col-sm-7 col-md-6">
<div class="topbar-right">
<ul class="topbar-menu">
<li><a href="contact-quote.html" title="Give Feedback">Give Feedback</a></li>
<li><a href="contact-quote.html" title="Contact Us">Contact Us</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<!-- NAVBAR SECTION -->
<div class="navbar navbar-main">
<div class="container container-nav">
<div class="row">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<a class="navbar-brand" href="index.html">
<img src="images/logo-stiky.png" alt="RENOVAS" />
</a>
<nav class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="index.html" >HOME</span></a>
</li>
<li class="dropdown">
<a href="about-company.html">ABOUT US</a>
</li>
<li class="dropdown">
<a href="services-2.html" >SERVICES</a>
</li>
<!-- <li class="dropdown">
<a href="project-grid.html" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" role="button" aria-haspopup="true" aria-expanded="false">PROJECTS </a>
</li> -->
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" role="button" aria-haspopup="true" aria-expanded="false">CONTACT <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="contact-quote.html">GET A QUOTE</a></li>
</ul>
</li>
</ul>
</nav>
</div>
</div>
</div>
</div>
<!-- BANNER -->
<div class="section banner-page">
<div class="container">
<div class="row">
<div class="col-sm-12 col-md-12">
<div class="title-page">Contact Us</div>
</div>
</div>
</div>
</div>
<!-- CONTACT -->
<div class="section contact">
<div class="container">
<div class="row">
<div class="col-sm-3 col-md-3">
<div class="widget contact-info-sidebar">
<div class="widget-title">
Contact Info
</div>
<ul class="list-info">
<li>
<div class="info-icon">
<span class="fa fa-map-marker"></span>
</div>
<div class="info-text">We are based in Atlanta, Georgia.</div> </li>
<li>
<div class="info-icon">
<span class="fa fa-phone"></span>
</div>
<div class="info-text">404.543.8627</div>
</li>
<li>
<div class="info-icon">
<span class="fa fa-envelope"></span>
</div>
<div class="info-text">info@renovas.co</div>
</li>
<li>
<div class="info-icon">
<span class="fa fa-clock-o"></span>
</div>
<div class="info-text">Mon - Sat 09:00am - 6:00pm</div>
</li>
</ul>
</div>
</div>
<div class="col-sm-9 col-md-9">
<div class="content">
<p class="section-heading-3">We will be happy to assist you!</p>
<div class="margin-bottom-30"></div>
<h3 class="section-heading-2">
I would like to discuss:
</h3>
<form action="php/form-process.php" class="form-contact" id="contactForm" data-toggle="validator" novalidate="none">
<div class="form-group">
<input type="text" class="form-control" id="p_name" name="name" placeholder="Full Name..." required="">
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<select class="form-control">
<option>Interior / Exterior Painting</option>
<option>Deck & Porch Staining</option>
<option>Electricity</option>
<option>House Remodeling</option>
<option>Tiling And Laminate Flooring</option>
<option>Plumbing</option>
<option>Feedback</option>
</select>
</div>
<div class="form-group">
<input type="email" class="form-control" name="email" id="p_email" placeholder="Enter Address..." required="">
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<input type="text" class="form-control" name="subject" id="p_subject" placeholder="Subject...">
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<textarea id="p_message" class="form-control" name="message" rows="6" placeholder="Write message"></textarea>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<div id="success"></div>
<button type="submit" class="btn btn-primary">ASK A QUOTE</button>
</div>
</form>
<div class="margin-bottom-50"></div>
<p></p>
</div>
</div>
</div>
</div>
</div>
<!-- INFO BOX -->
<div class="section info overlap-bottom">
<div class="container">
<div class="row gutter-20">
<div class="col-sm-4 col-md-4">
<!-- BOX 1 -->
<div class="box-icon-4">
<div class="icon"><i class="fa fa-phone"></i></div>
<div class="body-content">
<div class="heading">CALL US NOW</div>
Office: 404.543.8627
</div>
</div>
</div>
<div class="col-sm-4 col-md-4">
<!-- BOX 2 -->
<div class="box-icon-4">
<div class="icon"><i class="fa fa-map-marker"></i></div>
<div class="body-content">
<div class="heading">LOCATION</div>
We are based in Atlanta, Georgia.
</div>
</div>
</div>
<div class="col-sm-4 col-md-4">
<!-- BOX 3 -->
<div class="box-icon-4">
<div class="icon"><i class="fa fa-envelope"></i></div>
<div class="body-content">
<div class="heading">SEND US A MESSAGE</div>
General: info@renovas.co<br>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- FOOTER SECTION -->
<div class="footer">
<div class="container">
<div class="row">
<div class="col-sm-3 col-md-3">
<div class="footer-item">
<img src="images/logo-stiky.png" alt="logo bottom" class="logo-bottom">
<p style="font-size: 11px;">Diversified Services. Unvarying Quality.</p>
<!-- <div class="footer-sosmed">
<a href="#" title="">
<div class="item">
<i class="fa fa-facebook"></i>
</div>
</a>
<a href="#" title="">
<div class="item">
<i class="fa fa-twitter"></i>
</div>
</a>
<a href="#" title="">
<div class="item">
<i class="fa fa-instagram"></i>
</div>
</a>
<a href="#" title="">
<div class="item">
<i class="fa fa-pinterest"></i>
</div>
</a>
</div> -->
</div>
</div>
<div class="col-sm-3 col-md-3">
<div class="footer-item">
<div class="footer-title">
Our Services
</div>
<ul class="list">
<li><a href="#" title="Interior / Exterior Painting">Interior / Exterior Painting</a></li>
<li><a href="#" title="Deck & Porch Staining">Deck & Porch Staining</a></li>
<li><a href="#" title="Electricity">Electricity</a></li>
<li><a href="#" title="House Remodeling">House Remodeling</a></li>
<li><a href="#" title="Tiling And Laminate Flooring">Tiling And Laminate Flooring</a></li>
<li><a href="#" title="Plumbing">Plumbing</a></li>
</ul>
</div>
</div>
<div class="col-sm-3 col-md-3">
<div class="footer-item">
<div class="footer-title">
Get a Quote!
</div>
<p>Call us or write us and schedule a free consultation.</p>
<p><strong>Call</strong> <a href="tel:4045438627" style="color:#ffc31d;">404.543.8627</a> today.</p>
<form action="#" class="footer-subscribe">
<input type="email" name="EMAIL" class="form-control" placeholder="info@renovas.co">
<input id="p_submit" type="submit" value="send">
<label for="p_submit"><i class="fa fa-envelope"></i></label>
</form>
</div>
</div>
</div>
</div>
<div class="fcopy">
<div class="container">
<div class="row">
<div class="col-sm-12 col-md-12">
<p class="ftex">© 2018 Renovas Home Solutions - All Rights Reserved</p>
</div>
</div>
</div>
</div>
</div>
<!-- JS VENDOR -->
<script type="text/javascript" src="js/vendor/jquery.min.js"></script>
<script type="text/javascript" src="js/vendor/bootstrap.min.js"></script>
<script type="text/javascript" src="js/vendor/jquery.superslides.js"></script>
<script type="text/javascript" src="js/vendor/owl.carousel.js"></script>
<script type="text/javascript" src="js/vendor/bootstrap-hover-dropdown.min.js"></script>
<script type="text/javascript" src="js/vendor/jquery.magnific-popup.min.js"></script>
<script type="text/javascript" src="js/vendor/easings.js"></script>
<script type="text/javascript" src="js/vendor/isotope.pkgd.min.js"></script>
<!-- sendmail -->
<script type="text/javascript" src="js/vendor/validator.min.js"></script>
<script type="text/javascript" src="js/vendor/form-scripts.js"></script>
<script type='text/javascript' src='https://maps.google.com/maps/api/js?sensor=false&ver=4.1.5'></script>
<script type="text/javascript" src="js/script.js"></script>
What, exactly, does the error message say?
name undefined
email undefined
message undefined
Perhaps if you var_dump()
the $_POST
array at the beginning of your code before you start to check if $_POST["name"]
etc are empty?
Why are you not using validation?
Script from post #1
Notice three error checking lines at top of page:
<?php
declare(strict_types=1);
ini_set('display_errors', 'true');
error_reporting(-1);
$errorMSG = "";
// NAME
if (empty($_POST["name"])) {
$errorMSG = "Name is required";
} else {
$name = $_POST["name"];
}
// EMAIL
if (empty($_POST["email"])) {
$errorMSG .= "Email is required ";
} else {
$email = $_POST["email"];
}
// MESSAGE
if (empty($_POST["message"])) {
$errorMSG .= "Message is required";
} else {
$message = $_POST["message"];
}
$EmailTo = "info@renovas.co";
$Subject = "New Message Received From Client";
$Name = $_POST['name'];
$Email = $_POST['email'];
$Message = $_POST['message'];
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From:".$email);
// redirect to success page
if ($success && $errorMSG == ""){
echo "success";
}else{
if($errorMSG == ""){
echo "Something went wrong :(";
} else {
echo $errorMSG;
}
}
Result:
Notice: Undefined index: name in /home/john/www/zzz-001.php on line 32
Notice: Undefined index: email in /home/john/www/zzz-001.php on line 33
Notice: Undefined index: message in /home/john/www/zzz-001.php on line 34
Notice: Undefined variable: name in /home/john/www/zzz-001.php on line 39
Notice: Undefined variable: email in /home/john/www/zzz-001.php on line 42
Notice: Undefined variable: message in /home/john/www/zzz-001.php on line 45
Notice: Undefined variable: email in /home/john/www/zzz-001.php on line 49
Name is requiredEmail is required Message is required
Which of the two forms in your HTML are causing the error?
donboe
July 25, 2018, 8:36am
12
@nadjanavedo I think @Mittineague allready gave you the answer. After your validation you set the variables:
$Name = $_POST['name'];
// other variables
All with capitals. Then in your $body you use the same variables in lowercase:
$Body .= $name;
Variable names are case sensitive
nadjanavedo:
is the same HTML
No, the form right at the bottom of your HTML has far fewer fields that the form in the main part. I wondered which of these two forms is causing your error messages.
True, but the code also assigns those lower-case variable names during the checks to see whether the $_POST
fields are empty at the top of the code. The extra lines creating a second copy of the variables are just a confusion. Trying to send the email “from” the form-fillers address might or might not cause issues depending on the OPs mail server config.
Is your form-validation code causing a problem? I’m not an expert, but I’m guessing that the specification of “novalidate” is to allow some JS code to handle that side of things, which by the look of it is this code: http://1000hz.github.io/bootstrap-validator/
You don’t have a name on your <select>
tag, is that intentional?
system
Closed
October 24, 2018, 4:36pm
14
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.