Click here to Skip to main content
14,878,738 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hey I am having problem in sending form ans in my mail the name email and phone no. is working but the message part is not working can anyone pls check my code and help me
below is my php code

$recipient = '';
$subject = "php mail test";
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$sender = '';
// I'm assuming you're going to validate, sanitize, and escape $name, $email, and $message
$message = "You have received a new message from the user {$name}.\n" .
    "Here is their email:\n {$email}\n" .
    "Here is their phone no.:\n {$phone}\n" .
    "Here is the message:\n {$message}";
$headers = "From: $sender";
if ( 
  isset($_POST['name']) && !empty($_POST['name']) &&
  isset($_POST['email']) && !empty($_POST['email'])
) {
  // Valid POST.
  // mail code here.
} else {
  // Invalid POST inputs
if (mail($recipient, $subject, $message, $headers)) {
    echo "Message accepted";
} else {
    echo "Error: Message not accepted";

and this is my html code
<form id="styleForm" name="get_in_touch" method="post" action="contact.php">
	<input name="recipient" value="" type="hidden">
	<div class="form-group">
		<label class="hidden" for="contactName">Name</label>
		<input class="form-control input-lg" name="name" placeholder="Name" title="Name" id="contactName">
	<div class="form-group">
		<label class="hidden" for="contactEmail">Email</label>
		<input class="form-control input-lg" name="email" placeholder="Email" title="Email" id="contactEmail">
	<div class="form-group">
		<label class="hidden" for="contactPhone">Phone</label>
		<input class="form-control input-lg" name="phone" placeholder="Phone" title="Phone" id="contactPhone">
	<div class="form-group">
		<label class="hidden" for="contactComments">Comments</label>
		<textarea class="form-control input-lg" name="message" placeholder="Comments" title="message" id="contactComments"></textarea>
	<div class="form-group text-right">
		<label class="hidden" for="contactSubmit">Submit</label>
		<input type="submit" value="Send" class="btn btn-lg btn-primary" title="Send" id="contactSubmit">
	<input name="hCheck" type="hidden">

**pls help**
ps: i am a beginner

What I have tried:

umm i did try some stuff like changing the message to comments then back to messege but i did not really get how to do it
Updated 18-Apr-21 23:19pm
Richard MacCutchan 18-Apr-21 4:18am
What does "not working" mean? Please be specific about your problem and explain exactly where it occurs.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900