php works but shows no content - php

I was working on a form and i had to use php to send the data through email. I am really new to coding. I just started working with php. My form works i even receive emails through it but the php page shows up blank. I tried using echo and error reporting but nothing shows up no html code shows up either. Its probably a newbie mistake. My php code:
<?php
$name = $_POST['fullName'];
$email_address = $_POST['email'];
$phone = $_POST['phoneNumber'];
$gender = $_POST['gender'];
$country = $_POST['country'];
$age = $_POST['age'];
$headers = "From: noreply#domainname.com";
$to = 'someone#example.com';
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\ngender: $gender\n\ncountry: $country\n\nage: $age";
mail($to,$email_subject,$email_body,$headers);
return true;
echo "thank you"
?>

You have two options right now:
Remove the return true;
Move the echo "thank you"; before your return true;
You can read more about return here:
http://php.net/manual/en/function.return.php
Side-note: you forgot a semi-colon (;) after your echo:
echo "thank you";
//--------------^

Related

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.

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.

form field value inside a message title in php

I have a simple php script which I use in form on my website. It works fine, however in a title of a message I receive, I would like to have (next to the "Quote Request") a date taken from the field called "date". I was playing with this code but it didn't work. I know the answer is probably very simple, but I don't know php (yet). How can I do it?
Thank you for any help. The code below.
<?php
$addressto = "email#email.com";
$subject = "Quote Request";
$content = "Name: ".$_POST['name']."\n"
."Date: ".$_POST['date']."\n";
if(!$_POST['name'] || !$_POST['date']){
header("Location: ../quote.html");
exit;
}
$email = $_POST['email'];
if(mail($addressto, $subject, $content, 'From: Contact <'.$email.'>')){
header("Location: ../sent.html");
}
?>
You mean:
$subject = "Quote Request - {$_POST['date']}";
Make sure you're validating the user input so as not to get yourself exploited!
Simple. Change this:
$subject = "Quote Request - " . date("d-m-Y", strtotime($_POST['date']));
Is this what you wanted?
If I understood the question correctly, this should achieve what you need:
<?php
$addressto = "email#email.com";
$subject = "Quote Request ".$_POST['date'];
$content = "Name: ".$_POST['name']."\n"."Date: ".$_POST['date']."\n";
if(!$_POST['name'] || !$_POST['date'])
{
header("Location: ../quote.html");
exit;
}
$email = $_POST['email'];
if(mail($addressto, $subject, $content, 'From: Contact <'.$email.'>'))
{
header("Location: ../sent.html");
}
?>
Try This:
Change
$content = "Name: ".$_POST['name']."\n"
."Date: ".$_POST['date']."\n";
To
$content = "Name: ".$_POST['name']."\n
Date: ".$_POST['date']."\n";
If you want the date to be in the subject with "Quote Request", you could do the following:
$subject = "Quote Request ".$_POST['date'];

Need a PHP email send script for HTML an form

I have a single page portfolio website that I'm building and I have a contact form that I need to process using php send script. I'm a novice when it comes to PHP so I'm having trouble getting this to work. I've done some searching but I can't find what I'm looking for.
Here's what I have done, I copied this from a PHP contact page that I had built but the PHP and form are on the same page and I need an external send.php to process my form.
<?php
$error = ''; // error message
$name = ''; // sender's name
$email = ''; // sender's email address
$company = ''; // company name
$subject = ''; // subject
$comment = ''; // the message itself
if(isset($_POST['send']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$company = $_POST['company'];
$subject = $_POST['subject'];
$comment = $_POST['comment'];
if($error == '')
{
if(get_magic_quotes_gpc())
{
$message = stripslashes($message);
}
// the email will be sent here
// make sure to change this to be your e-mail
$to = "example#email.com";
// the email subject
// '[Contact Form] :' will appear automatically in the subject.
// You can change it as you want
$subject = '[Contact Form] : ' . $subject;
// the mail message ( add any additional information if you want )
$msg = "From : $name \r\ne-Mail : $email \r\nCompany : $company \r\nSubject : $subject \r\n\n" . "Message : \r\n$message";
mail($to, $subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n");
}
}
if(!isset($_POST['send']) || $error != '')
{
header("location: http://www.#.com/#contact");
}
?>
So for my form I want to have:
<form method="post" action="send.php" class="form">
I plan on using HTML5 and jQuery to validate the form, so I really only need the script to capture the info and send the email to a single address. After it sends I want the script to redirect back to the Contact page.
Edit:
I found a solution after spending a while on google.
http://www.website.com/#contact");
?>
For one thing, you haven't initialized the value for $message
$message = stripslashes($message);
You probably meant to use $comment instead of $message
Not sure what problem you're facing. Simply copy the PHP you have into a file called send.php and my first glance says it'll work if you change $message back to $comment and add error checking. If you still have issues, post back with more details.

Categories