405 Not Allowed Github PHP - php

I hosted my website on github.My contact form doesn't work.I used PHP and HTML to make it.Here are my php code lines
PHP:
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$emailFrom = $_POST['email'];
$mobile = $_POST['number'];
$message = $_POST['message'];
$mailTo = "vukstamenkovic9#zohomail.eu";
$headers = "From: ".$emailFrom;
$txt = "You have received an e-mail from ".$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: index.html?mailsent");
}
?>
When I want to contact,I always get this: 405 Not Allowed
How can I resolve this?I searched it and nothing showed up.I would really appreciate help.

Related

Hi, I am making a contact form thingy, and my php isn't working any reason why?

Error:
the code:
<?php
$name = $_POST['name'];
$mail = $_POST['mail'];
$message = $_POST['message'];
$to ="bejidev27#gmail.com";
$subject = "New contact from " .$name;
$body = "";
$body .= "Name : " .$name. "\r\n";
$body .= "Email : " .$mail. "\r\n";
$body .= $message. "\r\n";
if($mail !=NULL){
mail($to, $subject, $body);
header("Location: index.html") ;
header("Location: done.html") ;
}
?>
It's not sending the mail nor the page is working i need help ,thanks in advance :D
First, check if your servers are running properly. Then, for the following
$name = $_POST['name'];
$mail = $_POST['mail'];
$message = $_POST['message'];
There need to be values for each you. If you are getting the values from a form, then you have to handle the form first using the 'isset' function, to be able to pass the values to each variables.

How can I validate email in this PHP contact form? [duplicate]

This question already has answers here:
How to validate an email address in PHP
(15 answers)
Closed 3 years ago.
is there a way to validate an email in this form without rewriting it completely? It'd be great if I could just add something to this. I'm new to PHP and this form is taken from mmtuts video. If you know how to help, I'd be glad if you did.
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$number = $_POST['number'];
$subject = $_POST['subject'];
$mailFrom = $_POST['mail'];
$message = $_POST['message'];
$mailTo = "misavoz#seznam.cz";
$headers = "From: ".$mailFrom;
$txt = "Pan/í ".$name." vám poslal/a zprávu. Telefonní číslo: ".$number."\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: index.php?mailsend");
}
In the past I have used:
if(filter_var($email, FILTER_VALIDATE_EMAIL))
{
//send email
}
else
{
//show error
}
Source: https://www.php.net/manual/en/function.filter-var.php

PHP E-mail form - Define sender

I'm trying to create a HTML form, which will in the end send an e-mail using the folling PHP Code:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$destinationemail = "myemail#domain.com";
$emailcontent = "Name: {$name}\n\nE-Mail: {$email}\n\nMessage: {$subject}\n{$message}";
$subject = "Contact from Domain.com";
$from = $email;
mail($destinationemail, $subject, $emailcontent) or die("Error!");
echo "Thank you $name!";
?>
The problem is, everytime i receive an e-mail, i get is as if being sent from a what i guess is the Webhost general e-mail.
htgkaylg#server776.web-hosting.net
<htgkaylg#server776.web-hosting.net>
dom 08/10/2017, 18:40
Você;
I would like it to be received something like this:
myemail#domain.com
<myemail#domain.com>
dom 08/10/2017, 18:40
Você;
Is it possible?
Thank you,
Vítor
You have to use the Header as 4th parameter in mail() function.
Add this line and change mail as follow:
$headers = "From:" . $from . "\r\n";
mail($destinationemail, $subject, $emailcontent, $headers) or die("Error!");
Ref. https://www.w3schools.com/php/func_mail_mail.asp

Problems with contact form and input validation

Ok so I am trying to create a contact form that validates user input to keep hackers from submitting codes and trying to require number, text, and email only. I have already styled the form and imported my php file. The contact from will send it to my gmail account. but everytime I test the php It allows for any type of data to be entered no matter if it is supposed to be a number and letters are submitted and the other way around. If I could get some help in telling me where I went wrong that would be great. I am a beginner at programming and only have the knowledge I recieved from school but I'm pretty good at html and css but having problems with the php validation. The form sends the email but like I said it allows any and all input.
<?php
$name = $_POST['name'];
$tel = $_POST['tel'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: www.webdesignheros.com';
$to = 'heenanwrk#gmail.com';
$subject = 'Service Email for HeenanTech';
$tel = filter_input(INPUT_POST, 'tel', FILTER_SANITIZE_INT);
$name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING|FILTER_FLAG_NO_ENCODE_QUOTES);
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
$message = filter_input(INPUT_POST, 'message', FILTER_SANITIZE_STRING|FILTER_FLAG_NO_ENCODE_QUOTES);
$body = "From: $name\n Phone: $tel\n Email: $email\n Message: $message\n";
?>
<?php
if ($_POST['submit']){
if(mail($to, $subject, $body, $from)){
echo'<p>Thank you for your email!</p>';
} else {
echo '<p> Oops! Something went wrong, try sending your message again</p>';
}
}
?>
Additionally the form can be found at [http://webdesignheros.com/Contact.html][1]
[1]: http://webdesignheros.com/Contact.html and if someone could tell me how to reject certain input before the submit that would be awesome too. like if an invalid entry was input and they move on to the next input it would reject it and not let the submit button be pushed. would i use the pattern="a-z" in the html or would i need to add javascript for that?
<?php
if (isset($_POST["submit")){
$name = $_POST["name"];
$tel = $_POST["tel"];
$email = $_POST["email"];
$message = $_POST["message"];
$from = "From: www.webdesignheros.com";
$to = "heenanwrk#gmail.com";
$subject = "Service Email for HeenanTech";
$body = "From: $name\n Phone: $tel\n Email: $email\n Message: $message\n";
mail($to, $subject, $body, $from);
if(mail($to, $subject, $body, $from)){
echo'<p>Thank you for your email!</p>';
} else {
echo '<p> Oops! Something went wrong, try sending your message again</p>';
}
}
?>

how to resolve the situation if email does not received?

I wrote a code using php, html and css. This an contact form that is received by an email after submission. There is no error while submitting but i am not getting the email. I am including the code here. This is the link: http://complaintdesk.byethost15.com/contact.php.
Also I incude the code here.
contact.php
<?php
if(isset($_POST['submit'])){
$name = $_POST['fullname'];
$branch = $_POST['branch'];
$usn = $_POST['usn'];
$sem = $_POST['sem'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$description = $_POST['comment'];
$to = 'email#example.com';
$display = 'From:</br>Name: $name</br>USN: $usn</br>Branch: $branch</br>Semester: $sem</br>Email: $email</br></br>$description';
mail($to,$subject,$display);
echo "<script>alert('Your Complaint has been succesfully submitted, We will contact you soon.')</script>";
};
?>
And the rest of code i am not including...
Try this:
$to_address = "Your email address";
$subject = $_POST['subject'];
$headers = "MIME-Version: 1.0\r\n";
$headers.= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers.= "From: ".$email."\r\n";
if (mail($to_address,$subject,$description,$headers)){
echo "Success";
}
else{
echo "<h2>Unable to submit the form, please recheck the details.</h2>" ;
}
Update: If this does not work then there might be an error with your email configuration. As suggested by other users in the comments above, you might want to look into that part too. This answer is based on assumption that your email server/PHP is configured correctly.

Categories