Having trouble creating a PHP form in a web site - php

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.

Related

Trying to create a form vulnerable to mail header injection

Been stuck on this for a few days. I'm trying to reproduce an example of mail header injection I found (http://www.phpsecure.info/v2/article/MailHeadersInject.en.php). A post on the matter already exists (email header injection - example not working) but it didn't have any solution. I got a basic contact form using the POST method with three fields (From, Subject and Message) which are then used to send a mail. I need the user to be able to enter Unicode/Hexa characters in the fields.
For example if the user enters address%40gmail%2ecom I want the output in the SMTP payload to be From: address#gmail.com
If I hardcode $from = "address%40gmail%2ecom" the output is the wanted one.
However if I use the user input in the 'from' field of the form ie $from = $_POST['from'] the output I get when I check the debug log of my SMTP client is From: address%40gmail%2ecom. Am I doing something wrong with the encoding or is there some protection activated I have to get rid of ?
If that's relevant I'm using WAMPserver and PHP 7.1.
My code :
<html>
<head>
<meta http-equiv="content-type" content="text/html" />
<title>Vulnerable contact page</title>
<link rel="stylesheet" href="email.css"/>
</head>
<body>
<form method="POST" action="">
<fieldset>
<legend>Send us a mail</legend>
<label for="sender">From : </label>
<input type="text" name="from" id="sender">
</br>
<label for="subject">Subject : </label>
<input type="text" name="subject" id="subject">
</br>
<label for="message">Your message : </label>
<input type="text" name="message" id="message">
</fieldset>
<p>
<input type="submit" value="Send"/>
<input type="reset" value="Cancel"/>
</p>
</form>
<?php
if(isset($_POST['from'])) {
$to = "*********#gmail.com";
$from = $_POST['from'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = "From: $from\n";
mail($to, $subject, $message, $headers);
}
?>
</body>
</html>

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

Issue with contact form (html and php): 405 not allowed

I'm trying to make a very basic contact form using HTML and PHP. For some reason, however, when I click the "submit" button I get the error "405 Not Allowed". Why? How could I fix this? (I'm hosting my website on GitHub)
my HTML:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="send_form_email.php" method="POST">
<input type="text" name="name" placeholder="Full Name">
<input type="text" name="mail" placeholder="Your e-mail">
<input type="text" name="subject" placeholder="Subject">
<textarea name="message" placeholder="Message"></textarea>
<button type="submit" name="submit">Send e-mail</button>
</form>
</body>
</html>
my PHP:
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['mail'];
$message = $_POST['message'];
$mailTo = "example#gmail.com";
$headers = "From: ".$mailFrom;
$txt = "You have received an e-mail from ".$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: index.php?mailsend");
}
(PS. I wrote "example#gmail.com" just because I wanted to keep my personal e-mail private on here.
PPS. I have been trying to make a very simple contact form (you write your name mail and message and the owner of the website receives it in the inbox) but none of my (desperate) attempts seems to work. Can anyone help me out?)
Github is a hosting service for static web pages. PHP is not static. Deploying PHP to GitHub Pages - is it possible?

Email Submission form not working- Parse error

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>

Forms - PHP within HTML page, data not getting emailed

I am using PHP to send data to an email address from a HTML form. It worked fine while the PHP file was a pure PHP file, displaying the confirmation text upon submitting the form. However, I needed the confirmation text to appear within our usual templates so I added the same PHP into the body of a page and set the form action to go to that page. When someone now submits the form, an email does get sent but it contains none of the information from the form. Can you help?
HTML:
<form method="post" action="thank-you-page.html">
Email: <input name="email" type="text"><br />
Name: <input name="name" type="text"><br />
<h3>Your message</h3>
Subject: <input name="subject" type="text"><br />
Message:<br /> <textarea name="message" rows="15" cols="40"></textarea><br />
<input type="submit" />
</form>
PHP within body of thank-you-page.html:
<?php
$to = "myemail#email.com";
$subject = 'Feedback from online form';
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{print 'Your mail was sent successfully. Thank you for your feedback.'; }
else
{print 'We encountered an error sending your mail.'; }
?>
Thank you!
Your thank you page needs to be a PHP page, not just an HTML page.
Change it to be thank-you-page.php

Categories