Email Submission form not working- Parse error - php

So I am basically trying to create a simple photography portfolio website, and decided to put in a contact page as well. Right now I am trying to build a basic email submission form with php but when I inputted the values in the webpage the values disappeared, but I did not receive any emails. I was wondering if the cause is some error in my code, or if I have to turn the webpage into a website for it to send emails.
For furthermore information: I am using xampp to test out the php code and my file directories are: C:\xampp\htdocs and inside the htdocs is a folder called "Photo Website" which has all my webpages, and images.
I ran it through localhost using http://localhost/Photo%20Website/Contact.php and got
Warning : mail(): "sendmail_from" not set in php.ini or custom "From:" header missing in C:\xampp\htdocs\Photo Website\Contact.php on line 46
<!DOCTYPE html>
<html ng-app>
<head>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.7/angular.min.js">
</script>
<link rel="stylesheet" type="text/css" href="webpage.css">
</head>
<div id="nav">
<ul>
<li> Contact </li>
<li> About Me </li>
<li> Business </li>
<li> Street </li>
<li> Nature </li>
</ul>
<p id="logo"> Icyportraitsgta </p>
</div>
<div id="description">
<!-- Creating the contact forms using HTML !-->
<form method="post" name="emailform" action="Contact.php">
Enter Name: <input type="text" name="name"> <br>
Enter Email: <input type="text" name="email"> <br>
Message: <textarea name="message"></textarea> <br>
<input type="submit" value="Send">
</form>
<!-- Assigned variables using php and used POST !-->
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
?>
<!-- Using the above php variables to compose an email message !-->
<?php
$email_from = 'alihaider2011#live.ca';
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message";
?>
<!-- php code to send the email !-->
<?php
$to = "dutchland2013#hotmail.com";
$headers = "From: $email_from \r\n";
$headers = "Reply-To: $visitor_email \r\n";
mail($to, $email_subject,$email_body, $headers);
?>
</div>
</body>
</html>

Related

Having trouble creating a PHP form in a web site

I have created a web site and need to create a contact form that sends an email. I have created a contact.php form and my index.html file refers to it in the top menu under Contact Us. When you click on "Contact Us" it gives me an error of "This page isn’t working www.drjenniferjill.net is currently unable to handle this request.
HTTP ERROR 500".
I have tried a simpler test form and I received the same error. I have tried other examples with similar results.
<?php
if($_POST["submit"]) {
$recipient="drjennif#drjenniferjill.net";
$subject="Form to email message";
$sender=$_POST["sender"];
$senderEmail=$_POST["senderEmail"];
$message=$_POST["message"];
$mailBody="Name: $sender\nEmail: $senderEmail\n\n$message";
mail($recipient, $subject, $mailBody, "From: $sender
<$senderEmail>");
$thankYou="<p>Thank you! Your message has been sent.</p>";
}
<html>
<head>
<meta charset="utf-8">
<title>Contact form to email</title>
</head>
<body>
<?=$thankYou ?>
<form method="post" action="contact.php">
<label>Name:</label>
<input name="sender">
<label>Email address:</label>
<input name="senderEmail">
<label>Message:</label>
<textarea rows="5" cols="20" name="message"></textarea>
<input type="submit" name="submit">
</form>
When you click on "Contact Us" it gives me an error of "This page isn’t working www.drjenniferjill.net is currently unable to handle this request.
HTTP ERROR 500". I expected a form that can be completed to send an email.
<?php
if ($_POST["submit"]) {
$recipient = "drjennif#drjenniferjill.net";
$subject = "Form to email message";
$sender = $_POST["sender"];
$senderEmail = $_POST["senderEmail"];
$message = $_POST["message"];
$mailBody = "Name: $sender\nEmail: $senderEmail\n\n$message";
mail($recipient, $subject, $mailBody, "From: $sender <$senderEmail>");
$thankYou = "<p>Thank you! Your message has been sent.</p>";
}
?>
<html>
<head>
<meta charset="utf-8">
<title>Contact form to email</title>
</head>
<body>
<?=$thankYou ?>
<form method="post" action="contact.php">
<label>Name:</label>
<input name="sender">
<label>Email address:</label>
<input name="senderEmail">
<label>Message:</label>
<textarea rows="5" cols="20" name="message"></textarea>
<input type="submit" name="submit">
</form>
You need to close PHP tag ?> before starting your HTML markup
Also, please add these 3 lines at the beginning of your PHP script
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
It will start to display PHP errors instead of just This page isn’t working www.drjenniferjill.net is currently unable to handle this request. HTTP ERROR 500 and you can understand where do you have an error.

Issues with trying contact form that outputs to my email

So I'm in a web design class in school right now and I want to set up a contact page that will send the results to my email. I followed a really good tutorial and made sure I typed everything correct but it wont send. I'm using freehosting.com to host my pages.
Here's my index.php:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<meta charset="UTF-8">
<title>Email Form</title>
</head>
<body>
<main>
<p class="header">E-MAIL FORM</p>
<form class="contact-form" action="contactform.php" method="post">
<p class="title">Your Name</p>
<input type="text" name="name" placeholer="Full Name"><br/>
<p class="title">Your E-Mail</p>
<input type="text" name="mail" placeholer="Your E-mail"><br/>
<p class="title">Subject</p>
<input type="text" name="subject" placeholer="Subject"><br/>
<p class="title">Message</p>
<textarea name="message" maxrows="10" placeholder="Message"></textarea><br/>
<button type="submit" name="submit"><h2>SUBMIT</h2></button><br/>
</form>
</main>
</body>
Here's my contactform.php:
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['mail'];
$message = $_POST['message'];
$mailTo = "terryjtowell#terrytowell.com";
$headers = "From: ".$mailFrom;
$txt = "You have received an Email from ".$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: index.php?mailsend");
}
Any help would be great. I'm new to PHP but really familiar with html. the live link for the test contact form is terrytowell.com/test/index.php I've made sure to upload my code to a live hosting service so that I'll be able to use server-side scripting. Thanks
Your code is right. The problem comes from your hosting.
Freehosting.com won't allow you to use mail() function unless you pay for an addon. It's all explained here -> https://www.freehosting.com/client/knowledgebase.php?action=displayarticle&id=25

New to PHP. Can't figure out what is missing to send mail

I'm new to PHP and having a hard time getting the PHP to mail when the contact form is filled out and submit is pressed. I've posted the PHP and HTML files. Any help is very much appreciated.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Jaza Solutions - Contact</title>
<link rel = "stylesheet"
type = "text/css"
href = "jazasolutions.css" />
</head>
<body>
<div id = "header">
<img src="jazasolutions.png" alt = "Jaza Solutions, LLC">
</div>
<div id="nav">
<ul>
<li><a href=JazaSolutionsContact.html>Contact</a></li>
<li><a href=JazaSolutionsAboutUs.html>About Us</a></li>
<li><a href=JazaSolutionsCourses.html>Courses</a></li>
<li><a href=JazaSolutions.html>Home</a></li>
</ul>
</div>
<div class="sideRight">
<p> Jaza Solutions</p>
<p> 9818 Ushers Place </p>
<p> Waldorf, MD 20601 </p>
<br>
<p>301-861-2133</p>
<p>info#jazasolutions.com</p>
</div>
<div class = "main">
<p> Get the Management Certification you need to make the next step in your career! </p>
<br>
<p>SEND A MESSAGE</p>
<form class="contact-form" action="contactform.php" method="post">;
<input type="text" name="name" placeholder="Full Name">
<input type="text" name="mail" placeholder="Email">
<input type="text" name="subject" placeholder="Subject">
<textarea name="message" placeholder="Message"></textarea>
<button type="submit" name="submit">SEND MAIL</button>
</form>
</div>
</body>
</html>
The PHP code is posted here. This should send an email, but I can't figure out why it's not working.
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['mail'];
$message = $_POST['message'];
$mailTo = "pmckeown#jazasolutions.com";
$headers = "From: ".$mailFrom;
$txt = "You have received an email from ".$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: index.php?mailsend");
}
?>
I tried something similar a few years ago. After hours of searching I got a Tipp I'll never forget. The Mail RFC is so huge and has so many special cases that you don't do yourself a favor when you try to implement this on your own (Even if you get your Mail send it's most likely that it will be marked as spam from most of the Mail-Services out there because you missed some special handling or some tags). This becomes really funny when you try to send an attachment or even images in your mailer implementation. I'd recommend you try one of the proven Mail-Libraries for PHP like PHPMailer. You can expect that most of the common use-cases work out of the box without great problems.

PHP code error with contact form

I am beginner in web developing, I am building a website which has contact form and when the details are entered the details has to be sent to my mail id. But I am not sure why the code is not working.
<?php
if(isset($_POST["submit"])){
// Checking For Blank Fields..
if($_POST["name"]==""||$_POST["email"]==""||$_POST["note"]==""){
echo "Fill All Fields..";
}else{
// Check if the "Sender's Email" input field is filled out
$email=$_POST['email'];
// 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{
$message = $_POST['note'];
$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 removed ]", $message, $headers);
echo "Your mail has been sent successfuly ! Thank you for your feedback";
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Hire-a-Tent</title>
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="css/style.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="js/html5shiv.js"></script>
<![endif]-->
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<!-- Javascript -->
<script src="js/jquery.placeholder.js"></script>
<script src="js/custom.js"></script>
<!-- Fav and touch icons -->
<link rel="shortcut icon" href="favicon.ico">
</head>
<body>
<div class="background">
<div class="wrapper">
<header>
<div class="tel"><span>CALL US:</span> 9738479234 <br /><span style="padding-left:150px;">9731015469</span></div>
<div class="social">
<img src="images/facebook.png" alt="" />
<img src="images/twitter.png" alt="" />
</div>
</header>
<div class="sidebar">
<div class="order-form">
<div class="order-form-head">
<h1>Rent -a- Tent</h1>
</div>
<div class="taxi-line"></div>
<!-- Contact Form -->
<form action="email_code.php" id="form" method="post" name="form">
<div class="inp"><input type="text" class="required" name="name" id="name" placeholder="Name..." /></div>
<div class="inp"><input type="text" class="required" name="tel" id="tel" placeholder="Telephone..." /></div>
<div class="inp"><input type="text" class="required" name="email" id="email" placeholder="Email..." /></div>
<div class="inp"><textarea class="required" name="note" id="note" placeholder="Message..."></textarea></div>
<button type="submit"></button>
<div class="spacer"></div>
</form>
<?php include "email_code.php"?>
</div>
<div class="address-box">
<img src="images/icon.png" class="icon" alt="" />
<div class="text">
<span>We are located at</span><br />
85, 4th cross road,<br />
GKW layout, vijayanagar<br />
Bengaluru-40
</div>
</div>
</div>
<div class="character">
<!-- <img src="images/transparent2.png" class="taxi-driver" alt="" /> -->
<marquee behavior="alternate">T2 Tent: Rs 100/day --- T3 Tent: Rs 200/day -- Sleeping Bag: Rs 50/day --</marquee>
</div>
<div class="spacer"></div>
<footer>
<p><strong><br/><br/>Hire-a-tent</strong> © All Rights Reserved. <!--Developed by the Frequency Themes --></p>
</footer>
</div>
</div>
</body>
</html>
There are a few things wrong here, so please go over my entire answer carefully.
Firstly, your entire code's execution is relying on the conditional statement it's set in:
if(isset($_POST["submit"])){...}
where it is looking for and is relying on a named attribute of the same name, which would most likely be your submit button being:
<button type="submit"></button>
It needs to be named:
<button type="submit" name="submit"></button>
or use an input type with a name attribute:
<input type="submit" name="submit" value="Submit">
Then you have an undefined variable $email2 which would most likely need to be $email, as per:
$email=$_POST['email'];
Having used error reporting, would have both signaled an "Undefined index submit..." warning, as well as "Undefined variable email2...".
Add error reporting to the top of your file(s) which will help find errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
Sidenote: Error reporting should only be done in staging, and never production.
Now, this line:
mail("[ email removed ]", $message, $headers);
It is missing the "subject" parameter, which is an important parameter when using mail().
I.e.:
mail("[ email removed ]", $subject, $message, $headers);
therefore, you will need to add a variable for it.
I.e.:
$subject = "Form submission";
For more information on mail() and headers, visit:
http://php.net/manual/en/function.mail.php
From the manual:
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
To check if mail() has been in fact executed, change:
mail("[ email removed ]", $message, $headers);
to
if(mail("[ email removed ]", $message, $headers)){
echo "Mail has been sent.";
}
else{
echo "Error. Check your mail logs.";
}
If/when you see "Mail has been sent.", then mail() has done its job.
If you don't receive mail, then check your Spam or contact your hosting company if you're on a hosted site.
If you're running this from your own computer, then make sure that PHP and mail are in fact installed, running and configured properly.
Footnotes:
You're using the following twice, which one of them can be safely removed:
$email= filter_var($email, FILTER_VALIDATE_EMAIL);
EDIT:
To add other form variables to the message, first declare the POST variables:
$name=$_POST['name'];
$email=$_POST['email'];
$tel=$_POST['tel'];
Then change $message = $_POST['note']; to $comment = $_POST['note'];
and then do:
$message = "$name\n$email\n$tel\n$comment";
The \n adds line breaks.

PHP contact form not working and giving errors

I am trying to set up a contact form at:
http://48hrcodes.com/contact.php
however I am trouble getting it to work.
Here is the code I am using:
<?php
/**
* Change the email address to your own.
*
* $empty_fields_message and $thankyou_message can be changed
* if you wish.
*/
// Change to your own email address
$your_email = "";
// This is what is displayed in the email subject line
// Change it if you want
$subject = "48hrcodes contact form";
// This is displayed if all the fields are not filled in
$empty_fields_message = "<p>Please go back and complete all the fields in the form.</p>";
// This is displayed when the email has been sent
$thankyou_message = "<p>Thank you. Your message has been received.</p>";
// You do not need to edit below this line
$name = stripslashes($_POST['txtName']);
$email = stripslashes($_POST['txtEmail']);
$message = stripslashes($_POST['txtMessage']);
if (!isset($_POST['txtName'])) {
?>
<html lang="en">
<head>
<link href='https://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="css/style.css">
<title>Free 48hr Xbox Live Gold Codes</title>
</head>
<body>
<div id="content">
<div id="c1"> <center>
<header id="nav">
<ul>
<li>Home</li>
<li>Get Your Code</li>
<li>Testimonials and Proof</li>
<li>Frequently Asked Questions</li>
<li>Contact Us</li>
</ul>
</header>
<img class="clear" src="img/grab3.png" alt="header">
</center>
<form class="form" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<p class="name">
<input type="text" name="txtName" id="name" placeholder="John Doe" />
<label for="name">Name</label>
</p>
<p class="email">
<input type="text" name="txtEmail" id="email" placeholder="mail#example.com" />
<label for="email">Email</label>
</p>
<p class="text">
<textarea name="txtMessage" placeholder="Write something to us" /></textarea>
</p>
<p class="submit">
<input type="submit" value="Send" />
</p>
</form>
<div id="cttxt">
<h3>
Contact Us
</h3>
<p>
Simply send us message using the contact form to the left and we will get back to you within 24-48 hours.
</p>
</div>
<center>
<footer>
© 48hrcodes.com 2013 - site by ollie rex
</footer>
</div></center>
</div>
</body>
</html>
<?php
}
elseif (empty($name) || empty($email) || empty($message)) {
echo $empty_fields_message;
}
else {
// Stop the form being used from an external URL
// Get the referring URL
$referer = $_SERVER['HTTP_REFERER'];
// Get the URL of this page
$this_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"];
// If the referring URL and the URL of this page don't match then
// display a message and don't send the email.
if ($referer != $this_url) {
echo "You do not have permission to use this script from another URL, nice hacking attempt moron.";
exit;
}
// The URLs matched so send the email
mail($your_email, $subject, $message, "From: $name <$email>");
// Display the thankyou message
echo $thankyou_message;
}
?>
I get errors at the top of the page, as well as when i submit the form, the email i get only has the messagebox text, not the name or email.
I have tried everything i could think of, however it still fails to send anything except the msg variable.
Thanks :)
change
$name = stripslashes($_POST['txtName']);
$email = stripslashes($_POST['txtEmail']);
$message = stripslashes($_POST['txtMessage']);
To,
$name = (isset($_POST['txtName']))?stripslashes($_POST['txtName']):"";
$email = (isset($_POST['txtEmail']))?stripslashes($_POST['txtEmail']):"";
$message = (isset($_POST['txtMessage']))?stripslashes($_POST['txtMessage']):"";
To avoid the warnings at the top.
Use
like this
if(isset($_POST['txtName'])
{
$name = stripslashes($_POST['txtName']);
}

Categories