This question already has answers here:
How to run php files on my computer
(6 answers)
Closed 8 years ago.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>PHP form to email sample form</title>
<!-- define some style elements-->
<style>
label,a
{
font-family : Arial, Helvetica, sans-serif;
font-size : 12px;
}
</style>
<!-- a helper script for vaidating the form-->
<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>
</head>
<body>
<!-- Start code for the form-->
<form method="post" name="myemailform" action="wonder.php">
<p>
<label for='name'>Enter Name: </label><br>
<input type="text" name="name">
</p>
<p>
<label for='email'>Enter Email Address:</label><br>
<input type="text" name="email">
</p>
<p>
<label for='message'>Enter Message:</label> <br>
<textarea name="message"></textarea>
</p>
<input type="submit" name='submit' value="submit">
</form>
<script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
// for details
var frmvalidator = new Validator("myemailform");
frmvalidator.addValidation("name","req","Please provide your name");
frmvalidator.addValidation("email","req","Please provide your email");
frmvalidator.addValidation("email","email","Please enter a valid email address");
</script>
<p>
<!-- <a href='wonder.php' -->
>PHP form to email article page</a>
</p>
</body>
</html>
PHP form:
<?PHP
$email = $_POST["emailaddress"];
$to = "chris.pagemotion#gmail.com.my";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";
$message = "A visitor to your site has sent the following email address to be added to your mailing list.\n
Email Address: $email";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: chris.pagemotion#gmail.com.my\n";
$usermessage = "Thank you for subscribing to our mailing list.";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
?>
Do I need a local sever like xampp or phpMyAdmin to make this work? Or did I do something wrong?, it keeps giving me the PHP page text after I keep submit, I didn't set up a local host.
You will need a kind of web server where the PHP interpreter is running. I suggest to use a out-of-the-box solution like XAMPP or WAMP.
Related
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">
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>
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
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>
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 8 years ago.
I've looked everywhere on the web and I can't find a solution to my mail function. I've used xampp localhost and ive uploaded to a domain with no results.
My PHP code is:
<?php
//Grab from html form
$email = $_POST["email"];
$subject = $_POST["subject"];
$message = $_POST["message"];
$error = "";
//check if fields are filled
if (empty($subject)) {
$error = "Enter a subject";
}
if (empty($message)) {
$error .= "Enter a message";
}
echo $error;
//send email
mail($email, $subject, $message);
?>
The html code is below just in case...
<!DOCTYPE HTML>
<html>
<head>
<meta charset= "utf-8">
</head>
<body>
<form action="serverCode/mail.php" method="post">
Subject: <input type="text" name="subject"><br>
From: <input type="text" name="from"><br>
From Email: <input type="text" name="fromEmail"><br>
Message: <input type="text" name="message"><br>
To Email: <input type="text" name="email"
<input type="submit" value="Submit">
</form>
</body>
</html>
I'm just trying to make a simple webmailer in PHP.
It's probably due to a bad PHP configuration (specially if you are running XAMPP on Windows) or missing email headers. That was already asked many times. Check these links:
How to send an email using PHP?
php mail setup in xampp
Your HTML markup is incorrect:
The <input> element with the name "email" does not have a closing tag:
To Email: <input type="text" name="email"