Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
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("[email protected]", $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

    Member

  • Member
  • PipPipPip
  • 168 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

    Member

  • Member
  • PipPipPip
  • 168 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

    Member

  • Member
  • PipPipPip
  • 168 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