My form is sending a blank email (field data empty) to me every time i visit my site or refresh it.
I had a look at a few posts mentioning 'Post/Redirect/Get', but that confused me more than helped, and im not sure if it pertains to my exact issue.
This was a basic responsive form i found online and had to find the PHP to actually send the form data. (Changing it to suit my needs)
I'm hoping there's just an error i've missed somewhere but i cant seem to find it.
Any help would be greatly appreciated. Thanks in advance.
Here is the basic form (minus css):
PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n Email: $email \n Message: $message";
$recipient = "MY EMAIL HERE";
$subject = "Portfolio Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
HTML:
<form id="contact-form" action="/" method="post">
<h3>Say Hello!</h3>
<h4>Fill in the form below, and I'll get back to you as soon as i can. Thanks!</h4>
<div>
<label>
<span>Name: (required)</span>
<input placeholder="Please enter your name" type="text" name="name" tabindex="1" required autofocus>
</label>
</div>
<div>
<label>
<span>Email: (required)</span>
<input placeholder="Please enter your email address" type="text" name="email" tabindex="2" required>
</label>
</div>
<div>
<label>
<span>Telephone: (required)</span>
<input placeholder="Please enter your number" type="text" name="phone" tabindex="3" required>
</label>
</div>
<div>
<label>
<span>Message: (required)</span>
<textarea placeholder="Include all the details you can" type="text" name="message" tabindex="5" required></textarea>
</label>
</div>
<div>
<button name="submit" type="submit" id="contact-submit">Send Email</button>
</div>
</form>
use isset
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n Email: $email \n Message: $message";
$recipient = "MY EMAIL HERE";
$subject = "Portfolio Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
}
?>
it will post your email only when it submitted by any ..
i have post this one for other in stackoverflow link code link
this is my code.let try , i wish it will help you
<?PHP
$email = $_POST["emailaddress"];
$to = "you#youremail.com";
$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: you#youremailaddress.com\n";
$usermessage = "Thank you for subscribing to our mailing list.";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
?>
Related
So I have used the code:
<form action="../scripts/mail.php" method="POST">
<p>Name</p> <input type="text" name="name">
<p>Email</p> <input type="text" name="email">
<p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br />
<input type="submit" value="Send"><input type="reset" value="Clear">
</form>
and the php file linked is
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone Message: $message";
$recipient = "email#live.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='form.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>
The error when testing is: {"code":"MethodNotAllowedError","message":"POST is not allowed"}
What am I doing wrong?
There is no $phone variable defined yet you're trying to use it. Also see this in relation to Adobe products: https://community.adobe.com/t5/dreamweaver/quot-code-quot-quot-methodnotallowederror-quot-quot-message-quot-quot-post-is-not-allowed-quot-php/td-p/8967727?page=1
Try this, just to be double paranoid:
<form method="post" action="../scripts/mail.php">
<p>Name</p> <input type="text" name="name">
<p>Email</p> <input type="text" name="email">
<p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br />
<input type="submit" value="Send"><input type="reset" value="Clear">
</form>
mail.php :
if(isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent=" From: $name \n Email: $email Message: $message";
$recipient = "email#live.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='form.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
}
Is it a webpage or website?
If it is a web page you can install xampp(link - https://www.apachefriends.org/download.html). you have to move your file into "xampp/htdocs/" and then open "xampp control panel", click the start button in apache. Then go to your web browser and type as "localhost/yourfile.php/".Then the error message will not show.
if you want to send email watch this video -https://www.youtube.com/watch?v=KA2UB3pxEtg&t=26s
I've found some similar questions to my query, but none that fully match my situation.
I had a basic mail() PHP setup for use on the contact form on my website but, turns out this is blocked on my hosting server to avoid spam/abuse.
The web host recommends using SMTP as a workaround, but the tutorial they link to doesn't seem to provide a working solution for me!
This is my HTML:
<form action="php/mail.php" method="POST">
<p class="form-field-title">Name</p>
<input class="contact-field focus-hide" type="text" id="name" name="name" required autocomplete="off">
<p class="form-field-title">Email Address</p>
<input class="contact-field focus-hide" type="email" id="email" name="email" required autocomplete="off">
<p class="form-field-title">Phone</p>
<input class="contact-field focus-hide" type="text" id="number" name="number" autocomplete="off">
<p class="form-field-title">Message</p>
<textarea class="contact-field focus-hide" id="message" name="message" data-gramm_editor="false" required autocomplete="off"></textarea>
<input class="contact-button" type="submit" value="Send Message">
</form>
And this is my original (non-SMTP) mail.php code:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$message = $_POST['message'];
$formcontent="Name: $name \nEmail: $email \nPhone Number: $number \nMessage: $message";
$recipient = "email#email.com";
$subject = "Website Contact Form Enquiry";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
header('Location: ../thanks.html');
exit();
?>
I have the email server details for my web hosting, but none of the SMTP solutions I've found are working for me!
Is anyone able to help me? I've seen a few things about using PEAR, but their website doesn't seem to be working...?
Thanks!
If your form is in an email, I think you can't post data (maybe I'm wrong). But you can send it to your script with method get.
<form action="php/mail.php" method="GET">
</form>
Then update your php :
<?php
$name = $_GET['name'];
$email = $_GET['email'];
$number = $_GET['number'];
$message = $_GET['message'];
$formcontent="Name: $name \nEmail: $email \nPhone Number: $number \nMessage: $message";
$recipient = "email#email.com";
$subject = "Website Contact Form Enquiry";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
header('Location: ../thanks.html');
exit();
?>
It should do the job.
I receive an email but it will read from unknown. Everything else seems to work. Here is a link to the page link I don't know much about php.
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$mailTo = "contact#podmtg.com";
$headers = "From: ".$mailFrom;
$txt = "You have recieved an email from ".$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: contact.html?mailsend");
}
?>
<form action="contactform.php" method="post" onsubmit="return confirm('Are you sure you want to submit this form?');">
<input type="text" name="name" placeholder="Name" required="required">
<input type="text" name="email" placeholder="Email" required="required">
<textarea name="message" placeholder="Write message here..." required="required"></textarea>
<button type="submit" name="submit">SUBMIT</button>
</form>
In this you have mention this `$headers = "From: ".$mailFrom; but not $mailFrom found. Use $email in place of $mailFrom.
I changed the code. You guys were right. Thank you!
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$mailFrom = $_POST['email'];
$message = $_POST['message'];
$mailTo = "contact#podmtg.com";
$headers = "From: ".$mailFrom;
$txt = "You have recieved an email from ".$name.".\n\n".$message;
mail($mailTo, $headers, $txt);
header("Location: index.html?mailsend");
}
?>
Hello I have made a contact form on my website but even if the user doesn't type in any of the details and presses the submit button it sends me a blank email with nothing in it from Unknown Sender.
Anyone know why this is happening? I have added form validation so it shouldn't be sending anything.
HTML Code:
<form action="mail.php" method="POST">
<font color="red">*</font> Name <input type="text" name="name" required>
<font color="red">*</font> Phone <input type="text" name="phone" required>
<font color="red">*</font> Email <input type="text" name="email" required>
<font color="red">*</font> Message <input type="text" name="message" placeholder="I am looking for..." required><br />
<input type="image" src="images/Landing_Pages/submit.png" border="0" alt="Submit" />
</form>
PHP Code:
<?php $name = $_POST['name'];
$phone = $_POST['phone'];
$preferred = $_POST['preferred'];
$email = $_POST['email'];
$formcontent="From: $name \n Phone: $phone \n Email: $email \n Message: $message \n Preferred Contact: $preferred \n Email: $email";
$recipient = "bwebb#webbmaster.com.au";
$subject = "New Request Southbank";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
?>
You have to check if post data is not empty
if (!empty($name) && !empty($phone) && !empty($preferred) && !empty($email)) {
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
}
Edit
<?php
$name = $_POST['name'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$preferred = $_POST['preferred'];
$email = $_POST['email'];
$formcontent="From: $name \n Phone: $phone \n Email: $email \n Message: $message \n Preferred Contact: $preferred \n Email: $email";
$recipient = "bwebb#webbmaster.com.au";
$subject = "New Request Southbank";
$mailheader = "From: $email \r\n";
if (!empty($name) && !empty($phone) && !empty($message) && !empty($preferred) && !empty($email)) {
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
}
?>
Do something like :
$errorflag = 0 ;
if(empty($name)){$errorflag = 1 ;$error = "Input your Name plz!"; };
if(empty($phone)){$errorflag = 1 ;$error = "Input phone"; }
...
if(!$errorflag) {
#mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
}
check every input you need and then send
I'm trying to set up a simple contact form. Everything is styled correctly, but when I hit submit it doesn't take me anywhere, just attempts to open contact.php. I think there's something missing in the code that actually sends the message out. I'm sure it's something fairly simple that I'm missing, but this is a little over my head. Any help is appreciated.
<form action="mail.php" method="POST">
<p>Name</p> <input type="text" name="name">
<p>Company</p> <input type="text" name="company">
<p>Email</p> <input type="text" name="email">
<p>Phone</p> <input type="text" name="phone">
<p>Message</p><textarea name="message" rows="4" cols="25"></textarea><br />
<input type="submit" value="Submit">
</form>
<?php
$name = $_POST['name'];
$company = $_POST['company'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "______#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
$to ='______#gmail.com';
$send_contact=mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've received your information"
if($send_contact){
echo "We've received your contact information";
}
else {
echo "ERROR";
}
?>
EDIT: I was able to receive an email finally after adding the complete url for mail.php...however none of the information except for the message was included. The sender was listed as Apache...how can I assure that information entered in the forms will be included in the email? Thanks for all the help thus far.
since you are specifying code within the same page, you can omit action in your form.
Also, put a condition to run PHP once the script has been run.
<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$company = $_POST['company'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "______#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
$to ='______#gmail.com';
$send_contact=mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've received your information"
if($send_contact){
echo "We've received your contact information";
}
else {
echo "ERROR";
} }
?>
<form action = "<?= $_SERVER["PHP_SELF"]; ?>"method="POST">
<p>Name</p> <input type="text" name="name">
<p>Company</p> <input type="text" name="company">
<p>Email</p> <input type="text" name="email">
<p>Phone</p> <input type="text" name="phone">
<p>Message</p><textarea name="message" rows="4" cols="25"></textarea><br />
<input type="submit" value="Submit" name="submit">
</form>
Hope it helps!
EDIT: I am not sure what is the current filename but to keep it dynamic, I have mentioned $_SERVER["PHP_SELF"] which is not a recommended usage.
However, Try it! :)