Online contact form | Send email message using php | HTTP ERROR 405 - php

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!

Related

Bold text in PHP form (website contact to email)

I finally manged to get my contact form on my website to work, however, when it comes through via email, it's very plain. Would it be possible to try and get some words bolded under the email content settings? I'm new to all of this and I'm slowly learning but I've been stuck on this one for hours.
Content Code:
// Build the email content.
$email_content = "Name: $name\n";
$email_content .= "Email: $email\n\n";
$email_content .= "Company: $company\n\n";
$email_content .= "Message:\n$message\n";
Full Mailer.php code:
<?php
// Only process POST requests.
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the form fields and remove whitespace.
$name = strip_tags(trim($_POST["name"]));
$name = str_replace(array("\r","\n"),array(" "," "),$name);
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$message = trim($_POST["message"]);
$company = trim($_POST["company"]);
// Check that data was sent to the mailer.
if ( empty($name) OR empty($message) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
// Set a 400 (bad request) response code and exit.
http_response_code(400);
echo "Oops! There was a problem with your submission. Please complete the form and try again.";
exit;
}
// Set the recipient's email address.
// FIXME: Update this to your desired email address.
$recipient = "(my company email here)";
// Set the email subject.
$subject = "Website Query - $name $company";
// Build the email content.
$email_content = "<strong>Name:</strong> $name\n";
$email_content .= "Email: $email\n\n";
$email_content .= "Company: $company\n\n";
$email_content .= "Message:\n$message\n";
// Build the email headers.
$email_headers = "From: $name <$email>";
// Send the email.
if (mail($recipient, $subject, $email_content, $email_headers)) {
// Set a 200 (okay) response code.
http_response_code(200);
echo "Thank You! Your message has been sent.";
} else {
// Set a 500 (internal server error) response code.
http_response_code(500);
echo "Oops! Something went wrong and we couldn't send your message.";
}
} else {
// Not a POST request, set a 403 (forbidden) response code.
http_response_code(403);
echo "There was a problem with your submission, please try again.";
}
You would use standard html syntax.
So, send an email with bold text in it, you'd simply send
<b>Bold Text</b>
In your case, do this
$temp_message = trim($_POST["message"]);
//Find which part you want to bold or do this to make the whole thing bold.
$message = "<b>"+$temp_message+"</b>"

i have this error 'HTTP ERROR 500' when i submit this form. could anyone advise me on how to fix this?

I'm new to php and want to add a contact form to my website. i found this code but it doesnt seem to submit the form correctly. it comes up with this error 'HTTP ERROR 500' and i'm nt sure how to fix it.
This form is a simple one that i'm using on my portfolio website to allow users to write a message to me as well as leaving their email address and name.
my website is on godaddy on the linux cpanel server.
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$email_from = 'relay-hosting.secureserver.net';
$email_subject = "New form submission";
$email_body = "User name: $name.\n".
"User email: $visitor_email.\n".
"User message: $message.\n";
$to = "rosie.morrisgrove8#gmail.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");
?>
Thank you in advance
You are missing a ; at the end of your second last line.

Why is `mail()` in php not working with `LAMP(Linux Apache Mysql PHP`?

I am working on a contact us form, which sends an email to an email ID.
Following is the php script :
<?php
$name = $_POST['name'];
$phone = $_POST['phone'];
$visitor_email = $_POST['email'];
$email_from = "xxx#yyy.co.in";
$email_subject = "New form submission";
$email_body = "You have received a new message from the user $name";
$to = "xxx#yyy.co.in";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
$flag = mail($to,$email_subject,$email_body,$headers);
echo $flag;
?>
When I click Submit button I send a POST call to the page containing above script.
I receive form data correctly on that php page, but the email is not sent to the concerned email ID. The php mail() function returns false.
What may be the problem? Do I need to configure anything in the php.ini file?
I am working on Linux Mint and using LAMP.

PHP form adding recipent email

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.

.PHP email form sends but empty fields are received

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.

Categories