mail() function not working in php [duplicate] - php

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"

Related

PHP Ccontact form [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 2 years ago.
I'm trying to get this PHP form to work, every time I submit the form the browser returns the else statement but doesn't execute the above if statement, what have I missed?
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$mail = $_POST['mail'];
$message = $_POST['message'];
$to = '***.*****#gmail.com';
$subject='Form submission';
$message="Name: ".$name."\n". "Wrote the following: "."\n\n".$message;
$headers="From: ".$mail;
if (mail($to, $subject, $message, $headers)) {
echo "<h1>Sent Successfully! Thank you"." ".$name.", I will contact you shortly.</h1>";
}
else {
echo "Something went wrong! Contact me at alec.dannmayr#gmail.com";
}
}
?>
<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" cols="30" rows="10"></textarea>
<input type="submit" name="submit"></input>
</form>
There is something wrong with your mail() function.
Try looking in your maillog if anything is triggered at all. Usually located under /var/log/mail.log or /var/log/mail.err depending on your configuration. Have you tried sending the mail without the header (just to minimise possible errors).
It can be a pain to configure the mail() function to work properly. See this article, it might give you a hint. Is there a reason you want to use the mail() function a more advanced technique? You could use f.e. https://github.com/PHPMailer/PHPMailer which supports a better error/debugging management.

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?

My web form is not linking to my email [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
How can I send an email using PHP?
(20 answers)
Closed 6 years ago.
I am trying to create a web form for a website, but when I hit send, the page links to the .php file. Please tell me what I am doing wrong.
The .html and .php codes respectively look like this:
<form action="email.php" method="post">
<input class="input-text animated wow flipInY delay-02s" type="text" name="name" value="Your Name *" onFocus="if(this.value==this.defaultValue)this.value='';" onBlur="if(this.value=='')this.value=this.defaultValue;">
<input class="input-text animated wow flipInY delay-04s" type="text" name="email" value="Your E-mail *" onFocus="if(this.value==this.defaultValue)this.value='';" onBlur="if(this.value=='')this.value=this.defaultValue;">
<textarea class="input-text text-area animated wow flipInY delay-06s" name"description" cols="0" rows="0" onFocus="if(this.value==this.defaultValue)this.value='';" onBlur="if(this.value=='')this.value=this.defaultValue;">Describe your facilities and what you’re looking for. *</textarea>
<input class="input-btn animated wow flipInY delay-08s" type="submit" value="send message">
</form>
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$description = $_POST['description'];
$to = "Email Address";
$subject = "Facility and Other Specifications";
mail($to, $subject, $description "From: " . $name);
echo "Your message has been sent.";
?>
Also, I am not certain how to use PHP with the .php and .html files, or whether or not the operating system I am using (Snow Leopard) already comes with it.
I'm a little new to all of this, and any bit of information will be greatly appreciated.
If you mean what I think you do, it's linking to the literal code of your PHP file. From that, I can tell you that you probably don't have PHP installed. Thus, you need to install it.
Be sure your php code is in a separate document (email.php).
Extra: Change
mail ($to, $subject, $description "From: " . $name);
echo "Your message has been sent.";
to
$success = mail($to, $subject, $description "From: " . $name)
if($success){
echo "Your message has been sent.";
}else{
echo "Mail failure";
}
Right now your code is saying success even on a failure. The mail function returns true on success so you can just check the variable to see if it worked

how do i send email using php? [duplicate]

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.

My HTML contact form to PHP mail isn't working [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I have a decent understanding of HTML and CSS but completely novice when it comes to PHP. I've scouted the net and tried this out with multiple different tutorials, however I can't seem to tailor the php code to work with my contact page's email form. (www.richseeley.com/contact)
Ultimately, I would like this form to confirm the message being sent with a pop up window, without leaving the page, but so far I can't even get it to work in the most basic sense.
At present, it is echoing the "thank you for using our mail form", however the email isn't sending.
Here is the html coding for my contact form:
<div id="form-main">
<div id="form-div">
<form class="form" id="form1" action="scripts/test.php" method="post" enctype="text/plain">
<input name="name" type="text" class="feedback-input" placeholder="Name" id="name" />
<input name="email" type="text" class="feedback-input" id="email" placeholder="Email" />
<textarea name="message" class="feedback-input" id="message" placeholder="Message"></textarea>
<input type="submit" value="SEND" id="button-blue"/>
</form>
</div>
</div>
And here is the PHP code that I have most recently been trying to work with:
<?php
//send email
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
mail("r*******#gmail.com", $name,
$message, "From:" . $email);
echo "Thank you for using our mail form";
?>
I appreciate that this is a fairly simple problem I am trying to solve, but I've spent several hours with no success, and I really don't want to have to compromise the design of my work/website, and end up using something less stylised, as a basic tutorial would provide.
The only way I could think of doing it would be something like:
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
echo <p>Are you sure you want to do this?</p>
<form action="send_mail.php" method="post">
<input type="submit" name="ok" value="OK" />
<input type="submit" name="cancel" value="Cancel" />
</form>
?>
and in send_mail.php:
<?php>
//send email
if (isset($_POST['ok'])) {
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
mail("richsee******#****.com", $name,
$message, "From:" . $email);
echo "Thank you for using our mail form";
}
}
if (isset($_POST['cancel'])) {
header('Location: didnt_confirm.html");
}
?>
Also, your php seems wrong and vulnerable, but all you're asking is for a confirmation ;)
If you're concerned about vulnerability (header injections), you can read this.

Categories