apache doesn't show anything when I submit contact form - php

I know there are similar people that posted contact form help but I have an issue with mine. Everything works but when I submit I get an e-mail from apache that shows a blank message. However, when I use my own e-mail address in the form input , it works.
Here is my code
<?php
if(isset($_POST['submit'])){}
$name = $_POST['name'];
$email = $_POST['email'];
$minrooms=$_POST['mrooms'];
$message = $_POST['comment'];
$formcontent="From: $name \n Email: $email \n Min Number of Rooms: $minrooms\n Message: $message ";
$recipient = "kellito13#gmail.com";
$subject = "Contact Form";
$mailHeader = "From: $email \r\n";
send_contact= mail($recipient, $subject, $formcontent, $mailHeader) or die("Error!");
echo "Thank You!";
}
else{
echo"Error";
}
?>

You have syntax errors in your code with {} and send_contact= mail($recipient, $subject, $formcontent, $mailHeader) or die("Error!");.
It should be something like this:
<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$email = $_POST['email'];
$minrooms=$_POST['mrooms'];
$message = $_POST['comment'];
$formcontent="From: $name \n Email: $email \n Min Number of Rooms: $minrooms\n Message: $message ";
$recipient = "kellito13#gmail.com";
$subject = "Contact Form";
$mailHeader = "From: $email \r\n";
$send_contact= mail($recipient, $subject, $formcontent, $mailHeader) or die("Error!");
echo "Thank You!";
}
else{
echo"Error";
}
?>

Related

How do I make my contact page working in PHP?

I'm trying to make a simple contact page, but everytime I try to send a message, I get an error.
Here is the PHP code:
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "mailto:benten#benniestudios.eu";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $email, $formcontent, $mailheader) or die("Error!");
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
echo 'Return Home';
?>
What did I do wrong? If you need more info, please tell me.

Forum email address display issue

I created a web forum with the script below. I am able to receive inquiries from my site; however, the visitor's email address is not showing in the email sent from the webmaster. I would like to have some guidance here to fix the problem.
Here is my PHP script:
<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "abc#gmail.com";
$subject = "Contact Form";
mail($recipient, $subject, $formcontent) or die("Error!");
echo "Thank You!";
?>
Here is what I got from the webmaster:
From: xx
Message: xx
No email address listed in the email sent by the webmaster.
I found some similar scripts on the web with two additional rows:
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
This actually gives me an Error output.
How can I fix the issue?
Thanks!
The third parameter of mail() is just the actual body of the message, which you have saved as $message. The fourth variable is where you define the headers, and is where you define who the message is From. Note that you don't actually need to pass the message as a header, and as such, your variable $formcontent, shouldn't contain your From: header. However, you do need to provide carriage returns in the form of "\r\n" after the provided email address.
The modified code would look like this:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent = "From: $name" . "\r\n";
$recipient = "abc#gmail.com";
$subject = "Contact Form";
mail($recipient, $subject, $message, $formcontent) or die("Error!");
echo "Thank You!";
?>
Hope this helps! :)
You could add headers to the mail function.
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "abc#gmail.com";
$subject = "Contact Form";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: <$email>" . "\r\n";
mail($recipient, $subject, $formcontent, $headers);
FYI - I would santize and validate all POST values before using them in this manner

Phone number is not displaying in $formcontent of my PHP code

<?php
$Name = $_POST['Name'];
$Email = $_POST['Email'];
$Number= $_POST['Number'];
$Message= $_POST['Message'];
$formcontent="
Name: $Name \n
Number: $Number \n
Email: $Email \n
Message: $Message";
$recipient = "info#domain.com";
$subject = "Contact Form";
$mailheader = "From: $Email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
The number is not displaying but name, email, message are displaying in formcontent. Empty space is showing in place of number while execution.
san.
Try echoing the value of $_POST['Number']. If it's still an empty string, then there must be a problem on the process of fetching the data via post method or in your HTML field for Number.

PHP mail $email = $_POST['email'] in $recipients

I have the following php mail file :
<?php $name = $_POST['name'];
$email = $_POST['email'];
$choice = $_POST['choice'];$num = $_POST['num'];
$choice1 = $_POST['choice1'];$num1 = $_POST['num1'];
$phone= $_POST['phone'];
$town= $_POST['town'];
$formcontent="
Name: $name \n
Number: $phone \n
Choice: $choice Amount:$num
Choice: $choice1 Amount:$num1
Town: $town \n
Email: $email" ;
$recipient = "info#domain.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";?>
Can I add the $email to the recipients? I want to add the email entered in the form into the recipients that receive the email. (info#domain.com and the email entered in the form ($email = $_POST['email'];) will receive the email.
You can add multiple email addresses to $recipient by separating them with commas. Try this.
$recipient = "info#domain.com, $email";
Edit
Here is the whole thing.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$choice = $_POST['choice']; $num = $_POST['num'];
$choice1 = $_POST['choice1']; $num1 = $_POST['num1'];
$phone= $_POST['phone'];
$town= $_POST['town'];
$formcontent = "
Name: $name \n
Number: $phone \n
Choice: $choice Amount:$num
Choice: $choice1 Amount:$num1
Town: $town \n
Email: $email";
$recipient = "info#domain.com, $email";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank you";
?>

How to add text to email sent from a php contact form

Hi all this is the PHP im using:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n Message: $message";
$recipient = "sophiec#fdb.co.uk";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='contact.html' style='text-decoration:none;
color:#ff0099;'> Return Home</a>";
?>
Its working perfectly fine but i would like there to be some text sent with this email that says "This is from your website" or something similar to tell the recipient that it isnt spam (my client isn't tech friendly and sees everything plain text as spam). I'm very new to PHP with nearly 0 knowledge and have no idea how to add something like that. I did have a go at making a new variable with the string inside and then include that in the:
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
line but with no success. Thanks for taking the time any help would be welcome.
Change this line: $formcontent=" From: $name \n Phone: $phone \n Message: $message";
Add the content you want:
$formcontent="This is from your website\n From: $name \n Phone: $phone \n Message: $message";
Or if you want to change the subject, this line: $subject = "Contact Form";
Add the content you want:
$subject = "Contact Form - From your website";
You can either add it in the $subject or $message.
$subject = "Contact Form: This is from your website"; // OR
$message .= "This is from your website";
$formcontent='This is from your website\n From: ' . $name . '\n Phone: ' . $phone . '\n Message: ' . $message;

Categories