I have made a .PHP file that when the email form is filled out it sends it to my email address. Now this all works fine, I get the email, but, I get empty fields, here is the email I received from my test:
"Name:
Email:
Messages: "
as you see, all the fields are empty even though they were filled out.
Here is the code for the .php file:
<?php
$first_name = $_POST['name'];
$email_message = $_POST['email'];
$message = $_POST['message'];
$headers = "Website message";
$headers = "From: $_email";
$to = 'enquiries#ajmoger.co.uk';
$subject = 'AJ Moger website comment submission';
$message = "
Name: $first_name \n
Email: $email_message \n
Messages: $message \n";
mail($to, $subject, $message, $headers);
header("Location: thank_you.html");
die();
?>'
and here is the HTML code for the form:
The reason is enctype="text/plain" on your <form>. Remove that from your <form> code.
There seems like a bug was filed on this topic , but the status is closed. So it's better not to use that encoding type.
Related
I am trying to submit an online contact form by using PHP but I get error message "HTTP ERROR 405" in submission.
Hello everyone!
I am trying to setup an Online Contact Form by using PHP. You can see the code here:
https://codepen.io/p_demetriou/pen/mdjRvJz
Below you can see the code of PHP file send-email.php :
<?php
// Get the form data
$name = $_POST['name'];
$surname = $_POST['surname'];
$company = $_POST['company'];
$email = $_POST['email'];
$message = $_POST['message'];
// Set the recipient email address
$to = "contactvenusproperties#gmail.com";
// $to = 'recipient#example.com';
// Set the email subject
$subject = 'Venus Holdings | New Message from Online Contact Form';
// Build the email content
$email_content = "Name: $name\n";
$email_content = "Surname: $surname\n";
$email_content = "Company: $company\n";
$email_content .= "Email: $email\n\n";
$email_content .= "Message:\n$message\n";
// Build the email headers
$email_headers = "From: $name <$email>";
// Send the email
mail($to, $subject, $email_content, $email_headers);
?>
When i submit the form, i get the following error message:
*This page isn’t working
If the problem continues, contact the site owner.
HTTP ERROR 405*
Any ideas on how to solve this issue?
Many thanks!
This question already has answers here:
Relying on HTML 'required' for simple form validation
(4 answers)
Closed 1 year ago.
I am a beginner helping my aunt build a personal website. I have an HTML form where users can contact her (slightly simplified for clarity):
<form id = "contact-form" method = "post" action = "contact-form-handler.php">
<input name = "name" type = "text" required><br>
<input name = "email" type = "email" required><br>
<textarea name = "message" class = "form-control" required></textarea><br>
<input type = "submit" class = "form-control submit" value = "SEND MESSAGE">
</form>
The script contact-form-handler.php reads,
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$email_from = "SEND_EMAIL#ADDRESS.com";
$email_subject = "Message from fziastories";
$email_body = "Name: $name.\n".
"Email: $visitor_email.\n".
"Message: $message.\n";
$to = "RECIEVE_EMAIL#ADDRESS.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject, $email_body, $headers);
header("Location: index.html");
?>
This form works great. When I enter various tests, the message goes through perfectly. And when I don't enter a value for one of the three inputs, I am not able to hit the 'SEND MESSAGE' button.
Except, every once in a while, maybe once or twice a week, I receive an empty message with no values filled out. This is confusing to me because I figure the current setup precludes users from submitting the form without entering value but also through the tests I have ruled out the possibility that a valid response is being entered as blanks.
I would greatly appreciate any advice! If you have any follow-up questions, do not hesitate to ask. Thank you!
The required tag in HTML forms is not very secure!
You should always validate the data on your server.
This could look something like this:
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
if (empty($_POST['name']) || empty($_POST['email']) || empty($_POST['message'])) {
header("Location: index.html");
exit;
}
$email_from = "SEND_EMAIL#ADDRESS.com";
$email_subject = "Message from fziastories";
$email_body = "Name: $name.\n".
"Email: $visitor_email.\n".
"Message: $message.\n";
$to = "RECIEVE_EMAIL#ADDRESS.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject, $email_body, $headers);
header("Location: index.html");
?>
I have an contact form on my Wordpress blog. It currently cannot send the form submission to my email anymore. The message in my mail client as below:
"A message that you sent was rejected by the local scanning code that
checks incoming messages on this system. The following error was given:
"Relaying not permitted" "
I believe it needs authentication. So to solve that i need to input my client email and password into the PHP file. But I do not exactly how to input the email and password info into PHP file correctly?
My PHP code as below. Please show me how to input mail client info into this PHP file.
<?php
$name = $_POST['name'];
$pickupadd = $_POST['pickupadd'];
$pickuppc= $_POST['pickuppc'];
$dropoffadd= $_POST['dropoffadd'];
$dropoffpc= $_POST['dropoffpc'];
$phonenumber= $_POST['phonenumber'];
$useremail = $_POST['email'];
$message = $_POST['message'];
$formcontent=" From: $name \n Pick Up Address: $pickupadd \n Pick Up Post Code: $pickuppc\n Drop Off Address: $dropoffadd\n Drop Off Post Code:$dropoffpc\n Fone Number: $phonenumber\n Email: $useremail\n Message: $message";
$recipient = "myemail#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!") ;
echo "Thank You!";
?>
I am trying to send a simple email form, everything is working fine, however I keep receiving the recipient email at the end of the body message. I examined the PHP code but I couldn't find why is displaying that email again, here is the PHP code:
$name = $_POST['name'];
$company = $_POST['company'];
$website = $_POST['website'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$email_from = 'juano.diy#gmail.com';//<== update the email address
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Company: $company.\n".
"Website: $website.\n".
"Contact Email: $visitor_email.\n".
"Here is the message:\n$message.\n".
"\n".
$to = "juano.diy#gmail.com";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
I'm introducing these details in the form:
Name: xxx
Company: xxx
website: www.xxx.com
email: xxx#live.com
message: Hi testing email
and this is what I am receiving:
You have received a new message from the user Juan Camilo.
Company: Blitzar.
Website: www.stiktag.com.
Contact Email: juano.diy#live.com.
Here is the message:
Hi, testing website.
juano.diy#gmail.com
The problem is the last line (juano.diy#gmail.com), why am I receiving that address when I already added it to the header, I don't want to see it there, any ideas?
The last line of your $email_body is concatenating down.
$email_body = "You have received a new message from the user $name.\n".
"Company: $company.\n".
"Website: $website.\n".
"Contact Email: $visitor_email.\n".
"Here is the message:\n$message.\n".
"\n".
Replace the last line: "\n". with "\n"; - notice the semicolon. This terminates the assignment.
Who can i create an array with email form fields array.
if(isset($_POST['submit'])){
$content=array(
$name=$this->strip_tags($_POST['name']),
$email=$this->strip_tags($_POST['email']),
$phone=$this->strip_tags($_POST['phone']),
$address=$this->strip_tags($_POST['address']),
$city=$this->strip_tags($_POST['city']),
$subject=$this->strip_tags($_POST['subject']),
$message=$this->strip_tags($_POST['message'])
);
and then send it using the mail function.
Thank you in advance
You could just do this, which is a lot easier:
if(isset($_POST['submit'])) {
$to = "someone#example.com"; // send email to
$from = "Your Name <you#example.com>"; // send email from
$subject = "Form submitted"; // email subject
$body = "The form has been submitted!
Here's the form data that was submitted.
Name: ".$_POST['name']."
Email: ".$_POST['email']."
Phone: ".$_POST['phone']."
Address: ".$_POST['address']."
City: ".$_POST['city']."
Subject: ".$_POST['subject']."
Message:
".$_POST['message']."
Some other text under the form data here...";
$email = mail($to, $subject, $body, "From: $from");
if($email) { // you don't actually need this, it's just to make sure it sends :)
echo "Email sent successfully";
}
}
This will send an email with the form data submitted.
I hope this helps!