contact-form.php is not working - php

My php contact form is not sending any emails to me. Please help me.
The form code:
<form action="php/contact-form.php" id="contact-form">
<div class="alert alert-success hidden" id="contact-alert-success" dir="rtl"> <strong>זה עבד!</strong> תודה שיצרת קשר. נחזור אליך מיד! </div>
<div class="alert alert-danger hidden" id="contact-alert-error" dir="rtl"> <strong>שגיאה!</strong> משהו השתבש בשליחת ההודעה. </div>
<div class="form-group" dir="rtl">
<label class="sr-only" for="name"></label>
<input dir="rtl" type="text" class="form-control" value="" placeholder="שם" data-msg-required="נא להזין שם." name="name" id="name">
</div>
<div class="form-group" dir="rtl">
<label class="sr-only" for="phone"></label>
<input type="text" value="" placeholder="טלפון" data-msg-required="נא להזין טלפון." data-msg-email="נא להזין טלפון תקין." class="form-control" name="phone" id="phone" maxlength="10">
</div>
<div class="form-group" dir="rtl">
<label class="sr-only" for="email"></label>
<input type="email" value="" placeholder="דואר אלקטרוני" data-msg-required="נא להזין דואר אלקטרוני." data-msg-email="נא להזין כתובת תקינה." class="form-control" name="email" id="email">
</div>
<div class="form-group" dir="rtl">
<label class="sr-only" for="message"></label>
<textarea dir="rtl" placeholder="נא להזין את ההודעה..." data-msg-required="יש להזין הודעה." rows="6" class="form-control" name="message" id="message"></textarea>
</div>
<input type="submit" value="שלח הודעה" class="btn btn-default btn-block" dir="rtl" data-loading-text="טוען...">
</form>
the contact-form.php file is
<?php
session_cache_limiter('nocache');
header('Expires: ' . gmdate('r', 0));
header('Content-type: application/json');
// Enter your email address
$to = 'omanbbb#gmail.com';
if($to) {
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$fields = array(
0 => array(
'text' => 'Name',
'val' => $_POST['name']
),
1 => array(
'text' => 'Email address',
'val' => $_POST['email']
),
2 => array(
'text' => 'Message',
'val' => $_POST['message']
),
3 => array(
'numbers' => 'Phone',
'val' => $_POST['phone']
)
);
$message = "";
foreach($fields as $field) {
$message .= $field['text'].": " . htmlspecialchars($field['val'], ENT_QUOTES) . "<br>\n";
}
$subject = "New message from: $name";
$headers = '';
$headers .= 'From: ' . $name . ' <' . $email . '>' . "\r\n";
$headers .= "Reply-To: " . $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
if (mail($to, $subject, $message, $headers)){
$arrResult = array ('response'=>'success');
} else{
$arrResult = array ('response'=>'error');
}
echo json_encode($arrResult);
} else {
$arrResult = array ('response'=>'error');
echo json_encode($arrResult);
}
?>
Thank you very much.

you are not including the method in your form eg:
<form action="php/contact-form.php" id="contact-form" method="post">
which will allow your contact-form.php to access the values from the form inputs in the post super global array.

Related

HTML/CSS/PHP Contact Form Not Submitting

I have a contact form on a website, I'm testing it live on the website and the submit button works when nothing is in the text fields, but when it's filled out it doesn't send. I've tried changing different things about the HTML like the method="post" to method="POST", I tried removing the noValidate="noValidate" from the section. I tried changing $_REQUEST to $_POST in the PHP document. I'm kind of new to contact forms and PHP so it could be something simple, but I'd love to know what I did wrong.
HTML:
<form class="form-contact contact_form" action="contact_process.php" method="POST" id="contactForm" noValidate="noValidate">
<div class="row">
<div class="col-12">
<div class="form-group">
<textarea class="form-control w-100" name="message" id="message" cols="30" rows="9" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter Message'" placeholder = 'Enter Message'></textarea>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input class="form-control" name="name" id="name" type="text" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter your name'" placeholder = 'Enter your name'>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input class="form-control" name="email" id="email" type="email" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter email address'" placeholder = 'Enter email address'>
</div>
</div>
<div class="col-12">
<div class="form-group">
<input class="form-control" name="subject" id="subject" type="text" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter Subject'" placeholder = 'Enter Subject'>
</div>
</div>
</div>
<div class="form-group mt-3">
<button type="submit" class="button button-contactForm btn_4 boxed-btn">Submit</button>
</div>
</form>
And here is contact_process.php:
<?php
$to = "myemail#gmail.com";
$from = $_REQUEST['email'];
$name = $_REQUEST['name'];
$subject = $_REQUEST['subject'];
$number $_REQUEST['number'];
$cmessage = $_REQUEST['message'];
$headers = "From: $from";
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $from . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$subject = "This is a test subject.";
$logo = 'img/logo.png';
$link = '#';
$body = "<!DOCTYPE html><html lang='en'><head><meta charset='UTF-8'><title>Express Mail</title></head><body>";
$body .= "<table style='width: 100%;'>";
$body .= "<thead style='text-align: center;'><tr><td style='border:none;' colspan='2'>";
$body .= "<a href='{$link}'><img src='{$logo}' alt=''></a><br><br>";
$body .= "</td></tr></thead><tbody><tr>";
$body .= "<td style='border:none;'><strong>Name:</strong> {$name}</td>";
$body .= "<td style='border:none;'><strong>Email:</strong> {$from}</td>";
$body .= "</tr>";
$body .= "<tr><td style='border:none;'><strong>Subject:</strong> {$csubject}</td></tr>";
$body .= "<tr><td></td></tr>";
$body .= "<tr><td colspan='2' style='border:none;'>{$cmessage}</td></tr>";
$body .= "</tbody></table>";
$body .= "</body></html>";
$send = mail($to, $subject, $body, $headers);
echo "Thank you!";
?>

Message not showing on PHP form when email received

I tested to receive to my own email, for some reason I get everything but its not showing the content of what I type. It doesnt show the actual message when I receive it. Can anyone help? Thanks!
<div class="contact-heading">
</div>
<form role="form" class="contact-form" action="contact-us.php" method="post">
<div class="form-group">
<label class="" for="exampleInputPassword1">Name</label>
<input type="text" name="name" class="form-control" id="exampleInputPassword1" placeholder="Name:" required >
</div>
<div class="form-group">
<label class="" for="exampleInputEmail2">Email address</label>
<input type="email" name="email" class="form-control" id="exampleInputEmail2" placeholder="E-Mail:" required >
</div>
<div class="form-group">
<label class="" for="exampleInputEmail3">Company</label>
<input type="text" name="company" class="form-control" id="exampleInputEmail3" placeholder="Company:" required >
</div>
<div class="form-group">
<label class="" for="exampleInputEmail4">Message</label>
<textarea class="form-control textarea" name="message" rows="8" id="exampleInputEmail4" placeholder="Message:"></textarea>
</div>
<button type="submit" class="btn btn-submit">Submit</button>
</form>
</div>
<?php
$to = 'emailsample#yahoo.com';
$subject = "Contact us";
$name = stripslashes($_REQUEST['name']);
$email = stripslashes($_REQUEST['email']);
$company = stripslashes($_REQUEST['company']);
$message = stripslashes($_REQUEST['message']);
$msg .= "Name: ".$name."\r\n";
$msg .= "E-mail: ".$email."\r\n";
$msg .= "Company: ".$company."\r\n";
$message .= "Topicjk: ".$message."\r\n";
$msg .= "Subject: ".$subject."\r\n\n";
$msg .= "---Message--- \r\n";
$msg .= "\r\n\n";
$mail = #mail($to, $subject, $msg, "From:".$email);
if($mail) {
header("Location:contact-us.html");
} else {
echo 'Message could not be sent! Please try again.';
}
?>
Because you are not passing $message (which has content) to mail in this line.
Change from
$mail = #mail($to, $subject, $msg, "From:".$email);
To
$mail = #mail($to, $subject, $message, "From:".$email);
or
Change from
$message .= "Topicjk: ".$message."\r\n";
To
$msg .= "Topicjk: ".$message."\r\n";

PHP Contact form empty body (bootstrap)

I am having trouble with my contact form (from bootstrap). the php code as well as the html code are as seen below. Whenever I try the contact form, the body will be empty. Am I missing anything?
This is the html code:
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
<div class="row-fluid">
<div class="span5">
<label>First Name</label>
<input type="text" class="input-block-level" required="required" placeholder="Your First Name">
<label>Last Name</label>
<input type="text" class="input-block-level" required="required" placeholder="Your Last Name">
<label>Email Address</label>
<input type="text" class="input-block-level" required="required" placeholder="Your email address">
</div>
<div class="span7">
<label>Message</label>
<textarea name="message" id="message" required="required" class="input-block-level" rows="8"></textarea>
</div>
</div>
<button type="submit" class="btn btn-primary btn-large pull-right">Send Message</button>
<p> </p>
</form>
This is the PHP code:
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Email sent!'
);
$name = #trim(stripslashes($_POST['name']));
$email = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'mail#luckystarmaids.com';
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
Your name and email form elements don't have name attributes. Without them, they won't be posted to the form's action1, 2.
Add names to your inputs:
<input type="text" name="first_name" class="input-block-level" required="required" placeholder="Your Last Name">
Also you will need to handle first and last name in your PHP code, at the moment you're only looking for name.
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="">
<div class="row-fluid">
<div class="span5">
<label>First Name</label>
<input name=firstname type="text" class="input-block-level" required="required" placeholder="Your First Name">
<label>Last Name</label>
<input name=lastname type="text" class="input-block-level" required="required" placeholder="Your Last Name">
<label>Email Address</label>
<input name=email type="text" class="input-block-level" required="required" placeholder="Your email address">
<label>Subject</label>
<input name=subject type="text" class="input-block-level" required="required" placeholder="Subject">
</div>
<div class="span7">
<label>Message</label>
<textarea name="message" id="message" required="required" class="input-block-level" rows="8"></textarea>
</div>
</div>
<button type="submit" class="btn btn-primary btn-large pull-right">Send Message</button>
<p> </p>
</form>
Try also to handle the data on the server. Check at least if the values are send:
<?php
if ( isset( $_POST['firstname'] )
&& isset( $_POST['email'] )
&& isset( $_POST['subject'] )
&& isset( $_POST['message'] ) )
{
$name = #trim(stripslashes($_POST['name']));
$email = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'mail#luckystarmaids.com';
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $s
ubject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
if ($success)
{
echo json_encode(array(
'success'=> true,
'message'=>'Email sent, you recieve an email at ' . $email
));
}
}
else
{
echo json_encode(array(
'success' => false,
'message' => 'An error has occured, please try again.'
));
}
?>

Sending Form Data with Attachment

Ok, I've gotten the attachment working in the email and it's being sent correctly thanks to this bit that I found here
What this is getting me is an email with an attachment, but none of the other form data is being injected into the email. I'm sure it's a problem with the syntax that I'm using, but I con't for the life of me figure out what I'm doing wrong. I've looked at about a billion other form examples that I've found here (and other less helpful nooks and crannies of the web)
Also, before the downvotes pour in, I realize I haven't done any sort of validation yet, and I'm not forwarding the user to a success URL after the message has been sent. I'm just trying to get the script working the way I think it should before I start going nuts over validating it.
Here is the html for my form:
<form class="pure-form pure-form-stacked" enctype="multipart/form-data"
method="POST" action="mail.php">
<fieldset>
<legend>About You</legend>
<div class="pure-g">
<div class="pure-u-1 pure-u-md-1-3">
<label for="firstname">First Name</label>
<input id="firstname" name="firstname" type="text" required>
</div>
<div class="pure-u-1 pure-u-md-1-3">
<label for="lastname">Last Name</label>
<input id="lastname" name="lastname" type="text" required>
</div>
<div class="pure-u-1 pure-u-md-1-3">
<label for="email">E-Mail</label>
<input id="email" name="email" type="email" required>
</div>
<div class="pure-u-1 pure-u-md-2-3">
<label for="street">Street Address</label>
<input id="street" name="street" type="text">
</div>
<div class="pure-u-1 pure-u-md-1-3">
<label for="city">City</label>
<input id="city" name="city" type="text">
</div>
<div class="pure-u-1 pure-u-md-1-3">
<label for="zip">Zip</label>
<input id="zip" name="zip" type="text">
</div>
<div class="pure-u-1 pure-u-md-1-3">
<label for="phone">Phone</label>
<input id="phone" name="phone" type="tel" placeholder="xxx-xxx-xxxx" required>
</div>
</div>
<legend>About Your Company</legend>
<div class="pure-g" >
<div class="pure-u-1 pure-u-md-1-3">
<label for="companyname">Company Name</label>
<input id="companyname" name="companyname" type="text" required>
</div>
<div class="pure-u-1 pure-u-md-1-3">
<label for="companysize"># of Employees?</label>
<input id="companysize" name="companysize" type="number" required>
</div>
<div class="pure-u-1 pure-u-md-1-3">
<label for="companywebsite">Website</label>
<input id="companywebsite" name="companywebsite" type="url" required placeholder="eg www.mysite.com">
</div>
<div class="pure-u-1 pure-u-md-1-1">
<label for="companylogo">Upload your Logo</label>
<input id="companylogo" type="file" name="attachment[]" >
</div>
</div>
<button type="submit" class="pure-button pure-button-primary">Submit</button>
</fieldset>
And here is the php from 'mail.php'
<?php
if(isset($_POST['submit']))
{ //check form inputs
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$street = $_POST['street'];
$city = $_POST['city'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$companyname = $_POST['companyname'];
$companysize = $_POST['companysize'];
$companywebsite = $_POST['companywebsite'];
}
if( $_POST || $_FILES )
{
// email fields: to, from, subject, and so on
// Here
$from = "host#notareal.com";
$to = "setmeup#notareal.com";
$subject = "Setup Request from Free Setup Form";
$message = $firstname.$lastname.$email.$street.$city.$zip.$phone.$companyname.$companysize.$companywebsite;
$headers = "From: $from";
// boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
// multipart boundary
$message = "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n"."Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
fixFilesArray($_FILES['attachment']);
foreach ($_FILES['attachment'] as $position => $file)
{
// should output array with indices name, type, tmp_name, error, size
$message .= "--{$mime_boundary}\n";
$fp = #fopen($file['tmp_name'],"rb");
$data = #fread($fp,filesize($file['tmp_name']));
#fclose($fp);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: application/octet-stream; name=\"".$file['name']."\"\n"."Content-Description: ".$file['name']."\n" ."Content-Disposition: attachment;\n" . " filename=\"".$file['name']."\";size=".$file['size'].";\n"."Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
}
$message .= "--{$mime_boundary}--";
$returnpath = "-f" . $from;
$ok = #mail($to, $subject, $message, $headers, $returnpath);
if($ok){ return 1; } else { return 0; }
}
//This function will correct file array from $_FILES[[file][position]] to $_FILES[[position][file]] .. Very important
function fixFilesArray(&$files)
{
$names = array( 'name' => 1, 'type' => 1, 'tmp_name' => 1, 'error' => 1, 'size' => 1);
foreach ($files as $key => $part) {
// only deal with valid keys and multiple files
$key = (string) $key;
if (isset($names[$key]) && is_array($part)) {
foreach ($part as $position => $value) {
$files[$position][$key] = $value;
}
// remove old key reference
unset($files[$key]);
}
}
}
?>
That's because $_POST["submit"] is never set - your button doesn't have a name.

PHP files open while clicking on send

this is my code in HTML5
whenever i am clicking on send button ...
phpfiles open rather mailing on that mail id which I mentioned can anybody help me out please ???
<div class="col-md-6">
<div class="alert alert-success hidden" id="contactSuccess">
<strong>Success!</strong> Your message has been sent to us.</div>
<div class="alert alert-danger hidden" id="contactError">
<strong>Error!</strong> There was an error sending your message.</div>
<h2 class="short">
<strong>Contact</strong> Us</h2>
<form action="php/contact-form.php" id="contactForm" type="post">
<div class="row">
<div class="form-group">
<div class="col-md-6">
<label>Your name *</label>
<input type="text" value="" data-msg-required="Please enter your name." maxlength="100" class="form-control"
name="name" id="name" /></div>
<div class="col-md-6">
<label>Your email address *</label>
<input type="email" value="" data-msg-required="Please enter your email address."
data-msg-email="Please enter a valid email address." maxlength="100" class="form-control" name="email"
id="email" /></div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-12">
<label>Subject</label>
<input type="text" value="" data-msg-required="Please enter the subject." maxlength="100" class="form-control"
name="subject" id="subject" /></div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-12">
<label>Message *</label>
<textarea maxlength="5000" data-msg-required="Please enter your message." rows="10" class="form-control" name="message"
id="message"></textarea></div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<input type="submit" value="Send Message" class="btn btn-primary btn-lg" data-loading-text="Loading..." />
</div>
</div>
</form>
</div>
======================================================
and dis are my codes in php file...
<?php
session_cache_limiter('nocache');
header('Expires: ' . gmdate('r', 0));
header('Content-type: application/json');
// Enter your email address below.
$to = 'info#webppulse.com';
$subject = $_POST['subject'];
if($to) {
$name = $_POST['name'];
$email = $_POST['email'];
$fields = array(
0 => array(
'text' => 'Name',
'val' => $_POST['name']
),
1 => array(
'text' => 'Email address',
'val' => $_POST['email']
),
2 => array(
'text' => 'Message',
'val' => $_POST['message']
)
);
$message = "";
foreach($fields as $field) {
$message .= $field['text'].": " . htmlspecialchars($field['val'], ENT_QUOTES) . "<br>\n";
}
$headers = '';
$headers .= 'From: ' . $name . ' <' . $email . '>' . "\r\n";
$headers .= "Reply-To: " . $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
if (mail($to, $subject, $message, $headers)){
$arrResult = array ('response'=>'success');
} else{
$arrResult = array ('response'=>'error');
}
echo json_encode($arrResult);
} else {
$arrResult = array ('response'=>'error');
echo json_encode($arrResult);
}
?>
whenever i am clicking on send button ...
phpfiles open rather mailing on that mail id can someone help me out please ?
Change the following code
<form action="php/contact-form.php" id="contactForm" type="post">
with
<form action="php/contact-form.php" id="contactForm" method="post">
You Must have install localhost server Like xampp or wampp.
Then put files in
For Xampp : htdocx/ Put your file in htdocx folder and run.
Foe wampp: www/ put your file in www folder and run.
Turn your type="post" into a method="post". Also, you need to have your project placed into the htdocs folder of your WAMP directory and ensure that the WAMP server has been turned on.
You should always try a "Hello World" test first to ensure that everything is running correctly. Check out tutorials on the Web for this.

Categories