Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

PHP Form Issues

php css html

  • Please log in to reply

#1
SarahConkers

SarahConkers

    New Member

  • Member
  • Pip
  • 4 posts

Good morning all, 

 

I have been having some EXCRUCIATINGLY awful issues with my php code. I have been working pretty freakin hard to sort this dang thing out. So my question is, why is it not giving a result under the "Send Feedback" button and why is it sending me messages with only the message, no sender, no contact information.

E-mail Code:
<?php
if(isset($_POST["submit"])){
//Checking for blank Fields..

if($_POST["vname"]==""||$_POST["vemail"]==""||$_POST["vcompany"]==""|| $_POST["vphonenumber"]==""||$_POST["msg"]==""){
echo "Please fill out all fields. Thank you.";
}else{
// Check if the "Sender's Email" input field is filled out
$email=$_POST['vemail'];

// Sanitize e-mail address
$email =filter_var($email, FILTER_SANITIZE_EMAIL);
// Validate e-mail address
$email= filter_var($email, FILTER_VALIDATE_EMAIL);

if (!$email){
echo "Invalid Sender's Email";
}
else{
$subject = $_POST['Form Submission'];

$message = $_POST['msg'];

$headers = 'From:'. $email2 . "\r\n"; // Sender's Email
$headers .= 'Cc:'. $email2 . "\r\n"; // Carbon copy to Sender
// message lines should not exceed 70 characters (PHP rule), so wrap it
$message = wordwrap($message, 70);


// Send mail by PHP Mail Function
mail("s-conklin@airman-usa.com", $subject, $message, $headers);
echo "Your mail has been sent successfuly ! Thank you for reaching out to us!";
}
}
}
?>
Contact Form Code:
<!DOCTYPE html> 
<html>
<head>
    <meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
    <title>CompanyName - PageName</title>
    <meta http-equiv="Content-Language" content="en-us" />
    <meta http-equiv="imagetoolbar" content="no" />
    <meta name="MSSmartTagsPreventParsing" content="true" />
    <meta name="description" content="Description" />
    <meta name="keywords" content="Keywords" />
    <meta name="author" content="Sarah Conklin" />
    <style type="text/css" media="all">@import "css/master.css";</style>  <style type="text/css" media="all">@import "css/master.css";</style>
</head>
<body>


<div id="logo">
<img src="images/AIRMANa.png" />LOGO GOES HERE<br /><br/>
</div>


<ul>
<li><a href="index.html">Home</a></li>
<li><a href="#">Contact</a></li>
<li><a href="#">Directions</a></li>
</ul>




<div id="page-container">




<div id="content">
 <!-- feedback form starts here -->
 <p align="center">
 <div id="feedback" align="center">
  <!-- heading of the form -->
<h3>Contact Form</h3>
<p>This is Contact form. Send us an e-mail and we will get right back to you!</p>


<!-- feedback form form -->
<p class="clear" align="center">
<form id="form" action="#" method="post">
<input type = "text" name="vcompany" value="" placeholder="Your Company" />
<input type = "text" name="vname" value="" placeholder="Your Name"/>
<input type = "text" name="email2" value="" placeholder="Your Email"/>
<input type = "text" name="vphonenumber" value="" placeholder="Your Phone Number" />
<br /><label>Your Comments</label><br />
<textarea name="msg" placeholder="Type your text here..."></textarea>
<input type="submit" name="submit" id="send" value="Send Feedback"/>
</form>
<h3><?php include "secure_email_code.php"?></h3> </p>
 </div>
 </p>
 </div>




 <div id="footer">
<h4>AIRMAN USA
 Corporation &#8226; PO Box 1130 &#8226; 42 Interational PKWY &#8226; Adairsville, GA 30103</h4>
</div>
</div>


 </body> 
 <!-- body ends here -->


 </html> 

Thank you for any help.


  • 0

Advertisements


#2
MattFS

MattFS

    GeekU Freshman

  • GeekU Freshman
  • PipPip
  • 90 posts

According to the code you posted, there is no input in your form named "vemail". So that means your PHP script should always stop at line 5:
 

if( $_POST["vname"] == "" || $_POST["vemail"] == "" || $_POST["vcompany"] == "" || $_POST["vphonenumber"] == "" || $_POST["msg"] == "" ){
echo "Please fill out all fields. Thank you.";

Because there is no input named "vemail", $_POST["vemail"] will be NULL (or ""), and the script should echo the notification and then stop.

 

With the code you posted, I don't see a scenario where an email would ever be sent, so I'm not sure how you were receiving any messages at all.


Edited by MattFS, 23 February 2016 - 11:03 AM.

  • 0

#3
SarahConkers

SarahConkers

    New Member

  • Topic Starter
  • Member
  • Pip
  • 4 posts

According to the code you posted, there is no input in your form named "vemail". So that means your PHP script should always stop at line 5:
 

if( $_POST["vname"] == "" || $_POST["vemail"] == "" || $_POST["vcompany"] == "" || $_POST["vphonenumber"] == "" || $_POST["msg"] == "" ){
echo "Please fill out all fields. Thank you.";

Because there is no input named "vemail", $_POST["vemail"] will be NULL (or ""), and the script should echo the notification and then stop.

 

With the code you posted, I don't see a scenario where an email would ever be sent, so I'm not sure how you were receiving any messages at all.

 

alright I renamed the input in the form to vemail, but the problem is that I'm still receiving THIS.


  • 0

#4
MattFS

MattFS

    GeekU Freshman

  • GeekU Freshman
  • PipPip
  • 90 posts

In the following lines, you are referencing a variable $email2 that has not been initiated. I believe you want to use the $email variable.

$headers = 'From:'. $email2 . "\r\n"; // Sender's Email
$headers .= 'Cc:'. $email2 . "\r\n"; // Carbon copy to Sender

Do you have PHP errors/notifications turned on? If so, you should have seen a warning about the $email2 variable not being initiated. If not, it may help to temporarily turn them on in order to track down issues in your code. You easily enable them by adding the following lines to the top of your PHP code:

error_reporting(E_ALL);
ini_set('display_errors', 1);

  • 0

#5
SarahConkers

SarahConkers

    New Member

  • Topic Starter
  • Member
  • Pip
  • 4 posts

Alright errors are one. 

 

Turns out that the results for please fill out all fields and thank you for contacting us results are a css issue. So that's a head space error on my part. *feels like an idioth*

 

The next part is the actual parsing errors:

 

I get e-mails from the server mailer(1and1.com) instead of the actual e-mail. On top of that here are the list of errors:

 


Notice: Undefined index: Form Submission in /homepages/35/d564177742/htdocs/airmanusa/site_project/secure_email_code.php on line26

Notice: Undefined variable: email2 in /homepages/35/d564177742/htdocs/airmanusa/site_project/secure_email_code.php on line 30

Notice: Undefined variable: email2 in /homepages/35/d564177742/htdocs/airmanusa/site_project/secure_email_code.php on line 31

Notice: Undefined variable: headers in /homepages/35/d564177742/htdocs/airmanusa/site_project/secure_email_code.php on line 39
Your mail has been sent successfuly ! Thank you for reaching out to us!

 

You can find my php code here


  • 0

#6
MattFS

MattFS

    GeekU Freshman

  • GeekU Freshman
  • PipPip
  • 90 posts

Yeah, you still need to replace $email2 with $email in your PHP code, check my last post. Fix that and see what happens.

 

Change this:

$headers = 'From:'. $email2 . "\r\n"; // Sender's Email
$headers .= 'Cc:'. $email2 . "\r\n"; // Carbon copy to Sender

To this:

$headers = 'From:'. $email . "\r\n"; // Sender's Email
$headers .= 'Cc:'. $email . "\r\n"; // Carbon copy to Sender

Edited by MattFS, 23 February 2016 - 01:13 PM.

  • 0

#7
SarahConkers

SarahConkers

    New Member

  • Topic Starter
  • Member
  • Pip
  • 4 posts

I figured out my issues. Thank you.


  • 0






Similar Topics


Also tagged with one or more of these keywords: php, css, html

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP