Simple PHP form still not working - php

Im uploading my website at the moment. However, I do not get my PHP code to work. I do have an mail server set up with the correct e-mail address. But when I use the script and press the button to send the form it gives me a blank page and no e-mail showing in my mailbox.
Could someone help me please ?
Find below my coding:
<div id="thirdColumn">
<div id="contactOns">
<form action="send.php" method="post" class="form">
<p class="name">
<input type="text" name="name" id="name" placeholder="NAAM" />
</p>
<p class="email">
<input type="text" name="email" id="email" placeholder="EMAIL" />
</p>
<p class="text">
<textarea type="text" name="message" id="message" placeholder="BERICHT"></textarea>
</p>
<p class="submit">
<input type="submit" id="sent" value="VERSTUUR" />
</p>
</form>
</div> <!-- End contactOns -->
</div> <!-- End thirdColumn -->
And here my PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$mail_to = 'info#dereebokgrandcafe.nl';
$subject = 'Bericht van een bezoeker '.$name;
$body_message = 'From: '.$name."\n";
$body_message .= 'E-mail: '.$email."\n";
$body_message .= 'Message: '.$message;
$headers = 'From: '.$email."\r\n";
$headers .= 'Reply-To: '.$email."\r\n";
?>

Try:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$mail_to = 'info#dereebokgrandcafe.nl';
$subject = 'Bericht van een bezoeker '.$name;
$body_message = 'From: '.$name."\n";
$body_message .= 'E-mail: '.$email."\n";
$body_message .= 'Message: '.$message;
$headers = 'From: '.$email."\r\n";
$headers .= 'Reply-To: '.$email."\r\n";
mail($mail_to,$subject,$body_message,$headers);
?>

Unfortunately! You are missing mail function.
mail($mail_to,$subject,$body_message,$headers);

Add this line in the end of your script to test sending mail , and send.
if(mail(mail_to, $subject, $message, $headers)) echo 'Mail sent '; else echo 'problem !';

Related

Contact form sending emails without name, email and message

I have a problem with a contact form I'm building because it sends the message without sender info (name & email) and no message as well. And I need that. I tried the var_dump from another post I found but did not work.
HTML
<form action="form_process.php" class="contact_form" method= "post" onsubmit>
<ul>
<li><label for="name">name:</label><input type="text" required /></li>
<li><label for="email">email:</label><input type="email" name="email" required /></li>
<li><label for="message">message:</label><textarea name="message" cols="40" rows="6" required ></textarea></li>
<li><button class="submit" type="submit">Enviar</button></li>
</ul>
</form>
</div>
PHP
<?php
$name = var_dump($_POST['name']);
$email = var_dump($_POST['email']);
$message = var_dump($_POST['message']);
$to = "mmechenique#gmail.com";
$subject = "Nuevo mensaje formulario de contacto";
mail ($to, $subject, $message, "From: " . $name);
echo "Tu mensaje ha sido enviado, muchas gracias!";
?>
Try using your form this way:
<form action="form_process.php" class="contact_form" method= "post">
<ul>
<li><label for="name">name:</label><input type="text" name="name" required /></li>
<li><label for="email">email:</label><input type="email" name="email" required /></li>
<li><label for="message">message:</label><textarea name="message" cols="40" rows="6" required ></textarea></li>
<li><button class="submit" type="submit">Enviar</button></li>
</ul>
</form>
</div>
PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "mmechenique#gmail.com";
$subject = "Nuevo mensaje formulario de contacto";
mail ($to, $subject, $message, "From: " . $name);
echo "Tu mensaje ha sido enviado, muchas gracias!";
?>
Your HTML should look like:
<form action="form_process.php" class="contact_form" method="post">
<ul>
<li>
<label for="name">name:</label>
<input type="text" name="name" required />
</li>
<li>
<label for="email">email:</label>
<input type="email" name="email" required />
</li>
<li>
<label for="message">message:</label>
<textarea name="message" cols="40" rows="6" required ></textarea>
</li>
<li>
<button class="submit" type="submit">Enviar</button>
</li>
</ul>
</form>
Your PHP should look like:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "mmechenique#gmail.com";
$subject = "Nuevo mensaje formulario de contacto";
$headers = "From: Enter something here < email#mail.com >\r\n";
$headers .= "X-Sender: Enter something here < email#mail.com >\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$headers .= "X-Priority: 1\r\n"; // Urgent message!
$headers .= "Return-Path: email#mail.com\r\n"; // Return path for errors
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
mail ($to, $subject, $message, $headers);
echo "Tu mensaje ha sido enviado, muchas gracias!";
?>
I shouldn't be giving out the answer so easily because you should have done your research before posting your question but what the hell. Now you know for next time to do SOME research before posting your question.
EDIT:
<?php
$headers = "From: Enter your name < myemail#mail.com >\n"; //If you are the one sending the email enter your name here
OR
$headers = "From: ".$name." < ".$email." >\n"; // If you are the one the email is being sent to then try this header
$headers .= "X-Sender: Enter your name < myemail#mail.com >\n"; //Same logic applies for this guy
OR
$headers .= "X-Sender: ".$name." < ".$email." >\n"; //Same logic applies for this guy
?>

PHP not grabbing form information

I'm relatively new to PHP and I'm having trouble getting my PHP to take my form data and submit it in an email. The email sends to me with the plain text I have in it but all the form data isn't there. Does anybody have any ideas of what's wrong?
Here's the HTML:
<div id="box3" class="clearfix">
<form action="contact.php" method="post" enctype="text/plain">
<div id="greyContainer" class="clearfix">
<p id="text5">
Contact Us
</p>
<p id="text6">
Feel free to contact us and leave a message if you have any general questions!
</p>
<label id="formgroup">
<p id="text7">
Name:
</p>
<input id="name" type="text" value="Full Name" name="name"></input>
</label>
<label id="formgroup1">
<p id="text8">
Number:
</p>
<input id="phone_number" type="text" value="Phone Number" name="phone_number"></input>
</label>
<label id="formgroup2">
<p id="text9">
Email:
</p>
<input id="email" type="text" value="Email Address" name="email"></input>
</label>
<label id="formgroup3">
<p id="text10">
Message:
</p>
<textarea id="message_block" name="message_block" >Message or question...</textarea>
</label>
<p id="text11">
<span id="textspan">AVA Roofing & Siding<br />12 Arcade Ave.<br />Amherst, NY 14226<br />716.602.3947</span><br />
</p>
<img id="image1" src="img/envelope.png" class="image" />
<a href="thank_you.html">
<input id="input" type="submit" value="Submit" name="submit" ></input>
</a>
<div id="whiteLine" class="clearfix">
</div>
</form>
</div>
</div>
Here's the PHP:
<?php
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$to = "example#gmail.com" ;
$from = $_POST['email'] ;
$name = $_POST['name'] ;
$headers = "From: $from";
$subject = "AVA Roofing Contact Form";
$message2 = $_POST['message_block'];
$number = $_POST['phone_number'];
$message = "A visitor has submitted the following requirements. \n\nName: $name\n\nEmail: $email\n\nNumber: $number\n\nMessage: $message";
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to, $subject, $message, $headers);
$send = mail($to, $subject, $message, $headers);
if($send)
{header( "Location: http://www.example.com/folder/thank_you.html" );}
else
{print "We encountered an error sending your mail, please notify webmaster#YourCompany.com"; }
?>
You've got the wrong encoding on your form:
<form action="contact.php" method="post" enctype="text/plain">
^^^^^^^^^^^^^^^^^^^^^
Since you're telling the browser to send it as text/plain, it will not be processed by PHP. For this simple form, you don't need to specify ANY encoding. Just accept the defaults.
If you insist on specifying an encoding, it should be application/x-www-form-urlencoded for standard forms, or multipart/form-data if you're doing file uploads.
You can send to other file like file.php and in this file the action you would have something like this:
$recipiente = "your#email.com ";
$asunto = "Formulario";
$message ="name: ".$name."<br>";
$message .="email: ".$email."<br>";
$message .="coment: ".$coment."<br>";
$message = stripslashes($message);
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type:text/html; charset=iso-8859-1\r\n";
$headers .= "From: $email\r\n";
$headers .= "Reply-to: $email\r\n";
$headers .= "Cc: $email\r\n";
mail($recipiente,$asunto,$message,$headers);

My php Contact form isn't working properly

The contact form will only send an email will the words name email and message. I have been going over it for a few hours but nothing seems to be working.
Here is the contact php file (email is edited)
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$mail_to = 'outlook.com';
$subject = 'Message about Tejano Fest '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'index.html';
</script>
<?php
Here is the html segment it's related to:
<form method="post" name="contact" action="#contact">
<div class="left">
<label for="author">Name:</label>
<input name="author" type="text" class="input_field" id="author" maxlength="40" />
</div>
<div class="right">
<label for="email">Email:</label>
<input name="email" type="text" class="input_field" id="email" maxlength="80" />
</div>
<div class="clear"></div>
<label for="text">Message:</label> <textarea id="text" name="text" rows="0" cols="0"></textarea>
<input type="submit" class="submit_btn float_l" name="submit" id="submit" value="Send" />
</form>
Thank you in advance for any assistance.
change it (there are the name of input):
$field_name = $_POST['author'];
$field_email = $_POST['email'];
$field_message = $_POST['text'];
Enjoy your code!
Use this... your POST array values does not matching with your form field names .
<form method="post" name="contact" action="#contact">
<div class="left">
<label for="author">Name:</label>
<input name="cf_name" type="text" class="input_field" id="author" maxlength="40" />
</div>
<div class="right">
<label for="email">Email:</label>
<input name="cf_email" type="text" class="input_field" id="email" maxlength="80" />
</div>
<div class="clear"></div>
<label for="text">Message:</label> <textarea id="text" name="cf_message" rows="0" cols="0"></textarea>
<input type="submit" class="submit_btn float_l" name="submit" id="submit" value="Send" />
<?php
if(isset($_POST['submit'])){
$field_name = $_POST['author'];
$field_email = $_POST['email'];
$field_message = $_POST['text'];
$mail_to = 'test#outlook.com';
$subject = 'Message about Tejano Fest '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'index.html';
</script>
<?php
} }?>
Some other option to consider(of course after changing the values of the POST arrays), you may want to try using PhpMailer-http://phpmailer.worxware.com/?pg=examplebsendmail as maybe your hosting solution requires Smtp authourisation.

First Name and Message Not shown on body of email

i created a contact form php below, for some reason when I submit the entries, the First name shows up on the header but not the Body of the message. Same goes for message. Does anyone know the issue here?
PHP
<?php
$field_name = $_POST['first_name'];
$field_last = $_POST['last_name'];
$field_email = $_POST['cf_email'];
$field_city = $_POST['cf_city'];
$field_state = $_POST['cf_state'];
$field_postal = $_POST['cf_postal'];
$field_country = $_POST['cf_country'];
$field_profession = $_POST['cf_profession'];
$field_industry = $_POST['cf_industry'];
$field_job = $_POST['cf_job'];
$field_linkedin = $_POST['cf_linkedin'];
$field_facebook = $_POST['cf_facebook'];
$field_instagram = $_POST['cf_instagram'];
$field_message = $_POST['cf_message'];
$mail_to = 'membership#name.com';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message = 'From: '.$field_last."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'City: '.$field_city."\n";
$body_message .= 'State/Province: '.$field_state."\n";
$body_message .= 'Postal: '.$field_postal."\n";
$body_message .= 'Country: '.$field_country."\n";
$body_message .= 'Profession: '.$field_profession."\n";
$body_message .= 'Industry: '.$field_industry."\n";
$body_message .= 'Job: '.$field_job."\n";
$body_message .= 'LinkedIn: '.$field_linkedin."\n";
$body_message .= 'Facebook: '.$field_facebook."\n";
$body_message .= 'Instagram: '.$field_instagram."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('CourtSide House. Thank you for your submission');
window.location = 'index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to membership#name.com');
window.location = 'index.html';
</script>
<?php}?>
HTML
<pre><form method="post" action="contact.php">
<p>Contact<p>
<hr>
<div class="row half">
<div class="6u"><input type="text" class="text" placeholder="First Name*" name="first_name"></div>
<div class="6u"><input type="text" class="text" placeholder="Last Name*" name="last_name"></div>
<div class="12u"><input type="text" class="text" placeholder="Email*" name="cf_email"></div>
<div class="4u"><input type="text" class="text" placeholder="City*" name="cf_city"></div>
<div class="4u"><input type="text" class="text" placeholder="State/Province*" name="cf_state"></div>
<div class="4u"><input type="text" class="text" placeholder="Postal Code*" name="cf_postal"></div>
<div class="12u"><input type="text" class="text" placeholder="Country*" name="cf_country"></div>
<div class="4u"><input type="text" class="text" placeholder="Profession*" name="cf_profession"></div>
<div class="4u"><input type="text" class="text" placeholder="Industry*" name="cf_industry"></div>
<div class="4u"><input type="text" class="text" placeholder="Job Title*" name="cf_job"></div>
</div>
<p>Share Some Information About Yourself*<i><small class="small" id="small" style="font-size: 12px">(Please Place Link of Social Media Profile)</small></i></p>
<hr>
<div class="row half">
<div class="4u"><input type="text" class="text" placeholder="LinkedIn Profile*" name="cf_linkedin"></div>
<div class="4u"><input type="text" class="text" placeholder="Facebook Profile*" name="cf_facebook"></div>
<div class="4u"><input type="text" class="text" placeholder="Instagram Profile*" name="cf_instagram"></div>
</div
><div class="row half">
<div class="12u"><textarea name="message" placeholder="Message" ></textarea></div>
</div>
<div class="row">
<div class="12u">
<ul class="actions">
<li><input type="submit" class="button" value="Submit"></li>
</ul>
</div>
</div>
</form></pre>
You need to append to the variable $body_message instead of overwriting it as you do the second time you call it.
$body_message = 'From: '.$field_name."\n";
$body_message = 'From: '.$field_last."\n";
should be
$body_message = 'From: '.$field_name."\n";
$body_message .= 'From: '.$field_last."\n";
Probably you are confusing your e-mail clients with this:
$body_message = 'From: '.$field_name."\n";
$body_message = 'From: '.$field_last."\n";
1) You're missing the concatenation operator on your variable assignment:
$body_message = 'From: '.$field_name."\n";
$body_message = 'From: '.$field_last."\n";
should be
$body_message = 'From: '.$field_name."\n";
$body_message .= 'From: '.$field_last."\n";
^^^^^
HERE
2) You're message field is just called message:
$field_message = $_POST['cf_message'];
should be
$field_message = $_POST['message'];
Or change
<textarea name="message" placeholder="Message" >
to
<textarea name="cf_message" placeholder="Message" >
Message is not showing because you are using wrong key when retrieving it.
Update with following:
$field_message = $_POST['message']; // Textarea's name is message not cf_message
Then, first name is not showing because you're overwriting $body_message right after you assign $body_message with 'From: '.$field_name."\n";.
Update as follows:
$body_message = 'From: '.$field_name."\n";
$body_message .= 'From: '.$field_last."\n"; // Use .= not just =

Code to submit the email form without refreshing the page and without validation

I have created a contact form using requires attribute. Now i want to submit this email form without refreshing the page. When i googled it, I got with the validation code, i don't need validation because i used required attribute in my html. I just want that function which i can add so that the page wont be refreshed after submitting and email should go..
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML5 Contact Form</title>
<link rel="stylesheet" media="screen" href="styles.css">
</head>
<body>
<div id="contact">
<form class="contact_form" action="contact.php" method="post" name="contact_form">
<ul>
<li>
<h2>Contact Us</h2>
<span class="required_notification">* Denotes Required Field</span>
</li>
<li>
<label for="name">Name:</label>
<input type="text" id="name" name="name" placeholder="John Doe" required />
</li>
<li>
<label for="email">Email:</label>
<input type="email" name="email" id="email" placeholder="john_doe#example.com" required /> <span class="form_hint">Proper format "name#something.com"</span>
</li>
<li>
<label for="message">Message:</label>
<textarea name="message" id="message" cols="40" rows="6" required></textarea>
</li>
<li>
<button class="submit" id="submit_btn" type="submit">Submit Form</button>
</li>
</ul>
</form>
</div>
</body>
</html>
contact.php
<?php
$field_name = $_POST['name'];
$field_email = $_POST['email'];
$field_message = $_POST['message'];
$mail_to = 'babloopuneeth#gmail.com';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) {
?>
</script>
<?php
} else { ?>
<?php
}
?>
I dont know what to add inside if and else cases to achieve my objective? Please help me out..
You would have to use jQuery's ajax function to send a form without refreshing the page, here's the official documentation: http://api.jquery.com/jQuery.ajax/
Hope it helps!
Just use this as contact.php
<?php
$field_name = $_POST['name'];
$field_email = $_POST['email'];
$field_message = $_POST['message'];
$mail_to = 'babloopuneeth#gmail.com';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
?>

Categories