Not receiving email with PHP form - php

I'm trying to make a simple html form with php to send messages to a specific email. A friend sent me this form but since i'm very noobish in PHP i can't seem to figure out why i'm not receiving any emails...
This is my HTML CODE:
<div class="form">
<form id="contactform" action="mailer.php" method="post">
<p class="contact">NOME</p>
<input id="name" name="name" placeholder="Primeiro e Ășltimo nome" required type="text">
<p class="contact">EMAIL</p>
<input id="email" name="email" placeholder="exemplo#domĂ­nio.com" required type="email">
<p class="contact">MENSAGEM</p>
<textarea rows="6" required placeholder="Escreva aqui a sua mensagem"></textarea>
<br />
<input class="buttom" name="submit" id="submit" tabindex="5" value="ENVIAR" type="submit">
</form>
</div>
And this is my PHP:
<?php
$to = 'MYEMAIL#gmail.com';
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = 'From: '.$_POST['email'].'' . "\r\n" .
'Reply-To: MYEMAIL#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $name, $subject, $message, "From: MYEMAIL#gmail.com\n");
?>
Any help, please?

Your form is wrong:
<h2>Feedback Form</h2>
<?php
// display form if user has not clicked submit
if (!isset($_POST["submit"]))
{
?>
<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">
From: <input type="text" name="from"><br>
Subject: <input type="text" name="subject"><br>
Message: <textarea rows="10" cols="40" name="message"></textarea><br>
<input type="submit" name="submit" value="Submit Feedback">
</form>
<?php
}
else
// the user has submitted the form
{
// Check if the "from" input field is filled out
if (isset($_POST["from"]))
{
$from = $_POST["from"]; // sender
$subject = $_POST["subject"];
$message = $_POST["message"];
// message lines should not exceed 70 characters (PHP rule), so wrap it
$message = wordwrap($message, 70);
// send mail
mail("webmaster#example.com",$subject,$message,"From: $from\n");
echo "Thank you for sending us feedback";
}
}
?>

$name is not a parameter in the mail function. If you are trying to add the persons name somewhere, add it to the subject, message or define it as an additional parameter. Try taking $name out and see if it works without it.
PHP mail function

Related

Stop form refreshing and duplicate emails sent from form

First of all I am wondering if there is a way to make it so the page don't refresh on form submission but the boxes etc. are still all cleared.
But my main issue is, once I submit a form it sends an email. BUT.... now every time I refresh the page or go back on the website it sends the email again. I can also click the submit several times. Any help is greatly appreciated.
Code
<?php
if(isset($_POST['SubmitButton'])){
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "reviews#itssimplytech.co.uk";
$subject = "Simply Tech Contact Form";
$headers = "From: $email \r\n".
"Reply-To: $.email \r\n".
'X-Mailer: PHP/' . phpversion();
mail($recipient, $subject, $formcontent, $headers) or die("Error!");
}
?>
<form class="contact-form" action="" method="post">
<input type="text" name="name" placeholder="Name" required>
<input type="email" name="email" placeholder="Email" required>
<textarea rows="5" name="message" placeholder="Say Something..." required></textarea>
<input type="submit" name="SubmitButton" value="Submit">
</form> <!-- /.contact-form -->

php form bug. Doesn't send my email [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I have tried to resolve the issue myself (and some websites and questions here in Stockoverflow), but without success.
My problem is I'm trying to make my form actually send an email to the specified address down there, but it is absolutely not working. Any idea where my code is bugging?
here is a piece of it, can you see any mistake?
Thanks!
<?php
if(isset($_POST['submit'])){
$to = "email#gmail.com"; // this is my Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['name'];
$subject = "Form submission";
$subject2 = "Copy of your form submission";
$message = $first_name . " " . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
}
?>
<body id="getademo">
<div class="titlepage">
<h1 id="introdemo">GET IN TOUCH</h1>
<p id="mikshahf">We will get back to you soon!</p>
</div>
<div id="form1">
<div id="formform">
<form>
<p>
<input name="name" type="text" class="feedback-input" placeholder="Name" id="name" />
</p>
<p>
<input name="email" type="text" class="feedback-input" id="email" placeholder="Email" />
</p>
<p>
<textarea name="message" class="feedback-input" id="comment" placeholder="Message"></textarea>
</p>
<div class="submit">
<input name="submit" type="submit" value="SEND" id="button-blue"/>
</div>
</form>
</div>
</div>
</body>
As I stated in comments; <form> alone defaults to a GET method when POST isn't specifically implied.
Therefore, you need to add it.
<form method="post">
Error reporting would not have signaled an error. It actually failed on you silently.

Php contact form not working well

So I have built my website and I planned on using a php based contact page to send emails to my email address I made this and I receive an e-mail but no content or summary...
so here is my html:
<form action="Php/sendemail.php" method="POST">
<div id="form-inner">
<input type="text" class="input" name="name" id="name" placeholder="Name">
<input type="email" class="input" name="email" id="email" placeholder="E-mail">
<textarea class="input textarea" name="message" id="message" placeholder="Your message here"></textarea>
<input type="submit" class="button" value="Send message" id="button">
</div>
</form>
and here is my php:
$subject = "Contact form submitted!";
$to = 'email#example.com';
$body = <<<HTML
$message
HTML;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
mail($to, $subject, $message, $headers);
header('Location: /Contact.php');
?>
I really do not understand why this is happening if you can please help ! Thnaks
This is because you are not geeting the value from the $_POST superglobal:
$body = <<<HTML
$message
HTML;
should be:
$message = $_POST['message'];
$body = <<<HTML
$message
HTML;
Of course there are other ways to do this like just putting $_POST['message']; in the message body but this illustrates how to get the submitted form values.
(You will also want to do things like clean up (i.e. trim(), etc) the submitted values and also defend against header injections as well).

Unable to send mails in PHP contact form using 000webhost webmail [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 8 years ago.
I am using 000webhost webmail to receive emails using contact form but its not working.
contact.php
<form action="mailer.php" method="post">
<p>Name:</p>
<input type="text" name="name" />
<p>E-mail:</p>
<input type="text" name="email" />
<p>Subject:</p>
<input type="text" name="subject" />
<p>Message:</p>
<textarea name="message"></textarea></p>
<input class="send" type="submit" value="Send" name="submit">
</form>
mailer.php
<?php
$to = "xxx#xxxxx.com";
$subject = "Support requested by ".$_POST['name'];
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$headers = 'From: '.$_POST['email'].'' . "\r\n" .
'Reply-To: '.$_POST['email'].'' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$body = $message;
#mail($to, $subject, $body, $headers );
header( 'Location:thankyou.php' ) ; //replace with landing page.
?>
Nothing wrong with your html I tried it.
If you have chrome you can use the developer tool to debug and see if your requests are sent and if they are lending on the correct path :
In your mailer.php output the $_POST variable to make sure your data is landing there correctly,
echo "<pre>";
var_dump($_POST);
echo "</pre>";
You may also need to validate your html :
<form action="mailer.php" method="post">
<p>Name:</p>
<input type="text" name="name" >
<p>E-mail:</p>
<input type="text" name="email" >
<p>Subject:</p>
<input type="text" name="subject" >
<p>Message:</p>
<textarea name="message"></textarea>
<input class="send" type="submit" value="Send" name="submit">
</form>

PHP Mail HTML Comment Form Variables

Can you provide the proper syntax to pass the html form variables to php mailer?
The php is:
$comment = $_POST['comment'];
$email = $_POST['email'];
$to = 'sssff#gmail.com';
$subject = 'From Website';
$message = $comment;
$headers = 'From: $email';
mail($to, $subject, $message, $headers);
$message needs to contain the contents of $comment
$headers needs to display the contents of $email as return address
Can anyone help me with the proper syntax? Thank you
EDIT
To clarify, the email i receive from the php mailer does not contain the from address contained by $email, nor does the message contain the comments from $comment.
The email is sent fine, but does not contain those crucial elements.
If you'd like to look at the form it is:
<form class="cmxform" id="commentForm" method="POST" action="">
<label for="cname">Name</label>
<input id="cname" type="text" name="name" size="60" class="required" minlength="2" />
<label for="cemail">E-Mail</label>
<input id="cemail" type="text" name="email" size="60" class="required email" />
<label for="curl">URL</label>
<input id="curl" type="text" name="url" size="60" class="url" value="" />
<label for="ccomment">Your comment</label>
<textarea id="ccomment" type="text" name="comment" cols="72" rows="8" class="required"></textarea>
<div id="button2"><input class="submit" id="submit_btn" type="submit" value="Send Email"/></div>
</form>
Thank you for your help
$headers = 'From: $email';
^--- ^---
should be " instead. Single quoted strings do not interpolate variables, so you're using a literal $email as your From address, not someone#example.com.
$comment = $_POST['comment'];
$email = $_POST['email'];
$to = "$email";
$from = 'sender email';
$subject = 'message subject';
//Begin HTML Email Message
$message = "$comment";
//end of message
$headers = "From: $from\r\n";
$headers .= "Content-type: text\r\n";
mail($to, $subject, $message, $headers);

Categories