Issues with trying contact form that outputs to my email - php

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

Related

How to run php file with HTML file to check if the webpage can successfully send emails to someone

I'm trying to create a contact page for my portfolio, where the user could place in their email, subject, and their message and then click a button to send it. I already downloaded XAMPP and PHP and I have been checking the website on the localhost. However, every time I type in the necessary fields and send, it would open up my computers email app and place text into the message field. I don't want this - i'm trying to make the email send from the webpage.
Here is the code for my PHP file:
<?php
$subject = $_Post['subject'];
$visitor_email = $_Post['email'];
$message = $_Post['message'];
$email_body = $message;
$to = "randemail#gmail.com";
$headers= "From: $visitor_email\r\n";
$headers .= "Reply-To:$visitor_email\r\n";
mail($to, $subject,$message,$headers);
header("Location:index.html");
?>
here is the code to my contact page:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Game Design Projects | My Portfolio</title>
<link rel="stylesheet" href="css/styles.css">
<link href="https://fonts.googleapis.com/css2?family=Raleway:ital,wght#0,300;1,200;1,400;1,700&display=swap"
rel="stylesheet">
</head>
<body>
<div id = "MainBody">
<div class="contactmeborder">
<div class="PortObjname">
<h2>Reach Out</h2>
</div>
<form action="mailto:randemail#gmail.com" method="post" action = "PHP/contact-form-handler.php">
<input type="text" name="email" placeholder=" Email"><br>
<input type="text" name="subject" placeholder=" Subject"><br>
<textarea type="text" name="message" placeholder="Your Message"></textarea> <br>
<input type="submit">
</form>
</div>
</div>
<div class="Footer">
<p class="footinfo">footer</p>
</div>
</body>
</html>
The PHP/contact-form-handler.php holds what you see for the PHP part of this post.
The form action is using mailto:, but it should be pointed to the URL for your PHP script.
mailto: is for links on your site so that users can send emails a specific address.
I would also look into using an API service like SendGrid, MailGun, etc. to send emails instead of mail(). PHP's mail() function is very unreliable.
<form action="mailto:randemail#gmail.com" , action need to be the php_send_mail.php
It's open your mail client because that is the current settings. (mailto...)
Note: apparently you added twice action (just keep the proper one)
<form action="mailto:randemail#gmail.com" method="post" action = "PHP/contact-form-handler.php">

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>

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.

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.

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?

Categories