how to resolve the situation if email does not received? - php

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.

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.

405 Not Allowed Github 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.

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.

PHP error in form spam prevention

I have a problem with this code returning nothing but a blank page... I have followed several different tutorials to try and get this working, I am not a proficient PHP coder at all - But do have a little understanding. My server however, doesn't show error messages. So pinpointing this is rather hard for me to do!
I added this top section here to prevent spam using a hidden field on the html page that posts to this email page.
<?php
$if(isset($_POST['subject'],$_POST['Customer'],$_POST['Email'],$_POST['Phone'],$_POST['Comment'],$_POST['Product'],$_POST['Amount'],$_POST['Valid'])) {
$if(isset($_POST['Name']) && !empty($_POST['Name'])) {
echo "Spam Detected!";
Die();
}
Here is the email part that is supposed to send email once the above section determines that field "name" is empty.
$subject = $_POST['subject'];
$name = $_POST['Customer'];
$from = $_POST['Email'];
$phone = $_POST['Phone'];
$message = $_POST['Comment'];
$prod = $_POST['Product'];
$cash = $_POST['Amount'];
$valid = $_POST['Valid'];
$to = "email#email.com";
$body = 'HTML EMAIL CONTENT HERE...';
$headers .= "From: $from " . "Subject";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
mail($to,$subject,$body,$headers);
}
?>
Any and all help will be greatly appreciated!
Thanks
use this i see your code you use $if try if without $
if(isset($_POST['subject'],$_POST['Customer'],$_POST['Email'],$_POST['Phone'],$_POST['Comment'],$_POST['Product'],$_POST['Amount'],$_POST['Valid'])) {
if(isset($_POST['Name']) && !empty($_POST['Name'])) {
echo "Spam Detected!";
Die();
}
}

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.

Categories