Contact.php cropping away Name - php

I got a email.php from a website. How do you add an extra field to it, like phone number?
The original one I downloaded works fine.
Email comes as>>
From: Nuski
E-mail: my#email.com
Subject: Test
Message: Test mail
But when I add $field_phone = $_POST['cf_phone']; and $body_message = "Phone: ".$field_phone."\n";
The email comes without the Name of the sender. Like>>
Phone: 5559
E-mail: flex#f.com
Subject: reCaptcha test
Message: Email Test
Here is my HTML form
<form action="email.php" method="post">
<div class="col-sm-6">
<div class="form-group">
<input class="form-control" name="cf_name" type="text" id="name" placeholder="Your Name" required>
</div>
<div class="form-group">
<input class="form-control" name="cf_phone" type="text" id="phone" placeholder="Phone" >
</div>
<div class="form-group">
<input class="form-control" name="cf_email" type="email" id="email" placeholder="Your Email" required>
</div>
<div class="form-group">
<input class="form-control" name="cf_subject" type="text" id="subject" placeholder="Subject" required>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<textarea class="form-control btn-block" name="cf_message" id="comments" placeholder="Please include your address and item code for delivery" required></textarea><br>
</div>
<div class="form-group">
<input type="submit" class="btn btn-block" id="submit" value="Send Message">
</div>
</div>
<div class="col-sm-12">
<p class="contact-success">Your Message has been Successfully Sent!</p>
<p class="contact-error">Error! Something went wrong!</p>
</div>
</form>
Here is my email.php
<?php
$field_name = $_POST['cf_name'];
$field_phone = $_POST['cf_phone']; //added by me
$field_email = $_POST['cf_email'];
$field_subject = $_POST['cf_subject'];
$field_message = $_POST['cf_message'];
$mail_to = 'ask#aki.co';
$subject = 'Message from AkiYTeeS - '.$field_subject;
$body_message = "From: ".$field_name."\n";
$body_message = "Phone: ".$field_phone."\n"; //added by me
$body_message .= "E-mail: ".$field_email."\n";
$body_message .= "Subject: ".$field_subject."\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
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to ');
window.location = 'index.html';
</script>
<?php
}
?>

Replace:
$body_message = "Phone: ".$field_phone."\n"; //added by me
With:
$body_message .= "Phone: ".$field_phone."\n"; //added by me // You forgot a "." here
Also note that it's better to use \r\n unstead of just \r or \n as windows mac and linux each need a different of the 2 so by adding both it should always work

$body_message = "Phone: ".$field_phone."\n";
You have forgotten the concatenation operator in the above line.
use "." (dot)
$body_message .= "Phone: ".$field_phone."\n";

Related

Bootstrap contact form not sending emails (FormTools neither)

I've tried searching high and low for a resolution to get a contact form to send e-mails for a few days now. Currently using Bootstrap. My host allows you to install FormTools but, although the enquirys are visible within FormTools, e-mails still do not arrive.
<form action="contact.php" method="post">
<div class="row">
<div class="form-group col-md-6">
<label for="exampleInputName">Full name</label>
<input type="name" name="cf_name" class="form-control" id="exampleInputName1" aria-describedby="nameHelp" placeholder="Eg. John Smith">
</div>
<div class="form-group col-md-6">
<label for="exampleInputEmail1">Email address</label>
<input type="email" name="cf_email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="example#example.co.uk">
</div>
<div class="form-group">
<label for="exampleSelect1">Subject of enquiry</label>
<select class="form-control" name="cf_subject" id="exampleSelect1">
<option>CCTV & Security</option>
<option>Door Access</option>
<option>Electrical</option>
<option>Networking</option>
<option>PC Repairs</option>
<option>Smart Thermostats</option>
<option>Other</option>
</select>
</div>
<div class="form-group">
<label for="exampleTextarea">Message contents</label>
<textarea class="form-control" name="cf_message" id="exampleTextarea" rows="3" placeholder="My enquiry..."></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
contact.php:
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_subject = $_POST['cf_subject'];
$field_message = $_POST['cf_message'];
$mail_to = 'myemail#live.com';
$subject = 'Message from a site visitor '.$field_name;
$body_message .= 'From: '.$field_name."\n";
$body_message .= 'Subject: '.$field_subject."\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 if required.');
window.location = 'contact.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to myemail#live.com');
window.location = 'contact.html';
</script>
<?php
}
?>
I've not had much experience with PHP and I've tried a few samples of code but I feel like I'm making no progress and although I've tried searching, I'm unsure how to implement certain solutions.
If someone could help or guide me (even point out a mistake I've probably made myself) that would be amazing.
Thanks for your help!

Contact form sends email but has no message

I am having trouble with my PHP code for my website. The email is being sent but has no messages.
This is the email I get when it sends. It's empty.
Data I input in my contact form
I tested my php code without the css files and bootstrap, and received the email perfectly with the messages. But when I included everything, from css and bootstrap codes, I receive the email without any messages.
HTML CODE:
<div class="contact-form bottom">
<h2> We want to hear from you . Send us a message!</h2>
<form id="main-contact-form" name="contact-form" method="post" action="send_email_test.php">
<div class="form-group">
<input type="text" name="userName" class="form-control" required="required" placeholder="Name">
</div>
<div class="form-group">
<input type="email" name="userEmail" class="form-control" required="required" placeholder="Email Id">
</div>
<div class="form-group">
<textarea name="userMessage" id="message" required class="form-control" rows="8" placeholder="Your text here"></textarea>
</div>
<div class="form-group">
<input type="submit" name="submit" class="btn btn-submit" value="Submit">
</div>
</form>
</div>
This is my PHP code:
<?php
$field_name = $_POST['userName'];
$field_email = $_POST['userEmail'];
$field_subject = $_POST['userSubject'];
$field_message = $_POST['userMessage'];
$mail_to = 'info#mariamulan.com'; /* Add your email address here */
$subject = 'Message from website'.$field_name; /* Create your own subject */
$body_message .= 'From: '.$field_name."\n";
$body_message .= 'Email: '.$field_email."\n";
$body_message .= 'Subject: '.$field_subject."\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('Hey! Thanks for the message! We will try to reply to you as soon as possible!');
window.location = 'index.html'; /* Where you want to get directed */
</script>
<?php
} else { ?>
<script language="javascript" type="text/javascript">
alert('Sorry, your message was not sent! Please send an email to
hello.mariamulan#gmail.com instead.');
window.location = 'index.html'; /* Where you want to get directed
*/
</script>
<?php
}
?>
Verify that your form has the correct "name" attributes.
Your code is pretty dirty tho.

Return message status in page after send mail with php

I try to show a message in html page, after send an e-mail.
I don't want to use javascript with an alert, just a simple message after send button.
I made a contact php page with this code:
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_telefon = $_POST['cf_telefon'];
$field_message = $_POST['cf_message'];
$mail_to = 'diaconu.eduardstefan#gmail.com';;
$from = 'Mesaj nou de la:'.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Telefon: '.$field_telefon."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $from, $body_message, $headers);
?>
And in html page, i insert a contact form with this code:
<form action="contact.php" method="post">
<div class="form-group">
<label for="name">
Nume
</label>
<input type="text" name="cf_name" placeholder="" id="name" class="form-control" required="true">
</div>
<div class="form-group">
<label for="email">
Email
</label>
<input type="text" name="cf_email" placeholder="" id="email" class="form-control" required="true">
</div>
<div class="form-group">
<label for="phone">
Telefon
</label>
<input type="text" name="cf_telefon" id="phone" class="form-control">
</div>
<div class="form-group">
<label for="phone">
Mesaj
</label>
<textarea name="cf_message" placeholder="" rows="5" class="form-control" required="true">
</textarea>
</div>
<input class="btn btn-info" type="submit" value="Trimite" >
<?php if($send_mail) {
if($mail_status){
print "succes";
exit();
}
else {
print "eroare";
}
}
?>
</form>
Email was successfully sent, but the message isn't show. After press send button, contact form return a blank page. I want to return the same page with message. (ater refresh)
Maybe exist another way to do that? With get or something like that?
Thanks for help!
Place your PHP in the top of the page of where your contact form is.
then change: <form action="contact.php" method="post">
to
<form action="" method="post">
you also need to add name="submit" to your submit button field and then wrap:
if (isset($_POST['submit'])) {
// code
}
Also if you are trying to make sure people fill in all fields, you should use
if (!empty($var))
{
// code
} else
echo "Fill in this field please";
}
required fields can be easily bypassed by just using required within the html side.
EDIT: once all conditions are met you can simply add echo "thanks" or whatever message you want to beneath the mail() field for a success message which will output to the page above the form.
if($_POST){
// send mail code here
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_telefon = $_POST['cf_telefon'];
$field_message = $_POST['cf_message'];
$mail_to = 'diaconu.eduardstefan#gmail.com';;
$from = 'Mesaj nou de la:'.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Telefon: '.$field_telefon."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $from, $body_message, $headers);
if($mail_status){
echo 'mail send';
}else{
echo 'mail not send';
}
}
//place html code here below the php code
<form action="" method="post">
<div class="form-group">
<label for="name">
Nume
</label>
<input type="text" name="cf_name" placeholder="" id="name" class="form-control" required="true">
</div>
<div class="form-group">
<label for="email">
Email
</label>
<input type="text" name="cf_email" placeholder="" id="email" class="form-control" required="true">
</div>
<div class="form-group">
<label for="phone">
Telefon
</label>
<input type="text" name="cf_telefon" id="phone" class="form-control">
</div>
<div class="form-group">
<label for="phone">
Mesaj
</label>
<textarea name="cf_message" placeholder="" rows="5" class="form-control" required="true">
</textarea>
</div>
<input class="btn btn-info" type="submit" value="Trimite" >
</form>

My PHP/HTML form doesn't work

I have a contact form in my website and it doesn't work properly. I get the email but the email it's empty, I don't get the information from the form.
the part of the html in my index.html
<form role="form" form name="contactform" method="post" action="send_form_email.php">
<div class="form-group">
<label>Nombre</label> <input type="text" name="nombre" class="form-control" placeholder="Introduce tu nombre" >
</div>
<div class="form-group">
<label>Apellidos</label> <input type="text" name="apellidos" class="form-control" placeholder="Introduce tus apellidos" >
</div>
<div class="form-group">
<label>Email</label> <input type="emal" name="email" class="form-control" placeholder="Introduce tu email" >
</div>
<div class="form-group">
<label>Telefono</label> <input type="text" name="telefono" class="form-control" placeholder="Introduce tu telefono" >
</div>
<div class="form-group">
<label>Mensaje</label> <textarea name="mensaje" class="form-control" rows="7"></textarea>
</div>
<button type="submit" class="btn btn-default" value="Submit"> Enviar
</form>
</div>
the part of the php file called "send_form_email.php"
<?php
$nombre = $_POST['nombre'];
$apellidos = $_POST['apellidos'];
$telefono = $_POST['telefono'];
$email = $_POST['email'];
$mensaje = $_POST['mensaje'];
$formcontent=" $nombre $apellidos $email $telefono $mensaje";
$recipient = "deniz946#gmail.com";
$subject = "Subject from $nombre";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You! We will get back to you as soon as possible!" . " -" . "<a href='./index.php'> Back to site</a>";
?>
<input type="emal" name="email" class="form-control" placeholder="Introduce tu email" > change to
<input type="email" name="email" class="form-control" placeholder="Introduce tu email" >
you have typo in type attribute.
Try this
<?php
$nombre = $_POST['nombre'];
$apellidos = $_POST['apellidos'];
$telefono = $_POST['telefono'];
$email = $_POST['email'];
$mensaje = $_POST['mensaje'];
$formcontent = "{$nombre} {$apellidos} {$email} {$telefono} {$mensaje}";
$recipient = "deniz946#gmail.com";
$subject = "Subject from $nombre";
if(PHP_OS == "Linux" || PHP_OS == "Darwin") $new_line = "\n"; /* if Linux or Mac */
elseif(PHP_OS == "WINNT") $new_line = "\r\n"; /* if Windows */
$mailheader = "MIME-Version: 1.1" . $new_line;
$mailheader .= "Content-type: text/html; charset=utf-8" . $new_line;
$mailheader .= "From: ".$recipient.$new_line;
$mailheader .= "Return-Path: " . $recipient . $new_line;
$mailheader .= "Reply-To: " . $recipient . $new_line;
mail($recipient, $subject, $formcontent, $mailheader, "-r" . $recipient) or die("Error!");
echo "Thank You! We will get back to you as soon as possible!" . " -" . "<a href='./index.php'> Back to site</a>";
?>
Perhaps I can help you with an example I used myself:
The HTML contact Form:
<div class="row">
<!-- Content -->
<div id="content" class="8u skel-cell-mainContent">
<section class="12u">
<header>
<h2>Contact</h2>
</header>
<form method="post" action="mail.php">
<div class="row half">
<div class="6u">
<input name="subject" placeholder="Name" type="text" class="text" />
</div>
<div class="6u">
<input name='email' placeholder="Email" type="text" class="text" />
</div>
</div>
<div class="row half">
<div class="12u">
<textarea name="message" placeholder="Message"></textarea>
</div>
</div>
<div class="row half">
<div class="12u">
<!--a href="mail.php" class="button">Submit</a-->
<input type="submit" class="button" value="Submit">
</div>
</div>
</form>
</section>
</div>
The PHP processing of the form:
<?php
//mail(to,subject,message,headers,parameters)
// Check if the "from" input field is filled out
//if (isset($_POST['from']))
//{}
$to = 'mail#xxxxxx.com'; // my email address
$subject = $_POST['subject']; //name client
$feedback = 'thank you, we will reply soon.';
$header = $_POST['email']; //Email client
$message = $_POST['message'];
$message = wordwrap($message, 70);
$message = <<<EMAIL
Dear (YOUR WEBSITE NAME HERE),
My name is: $subject
$message
Email Client: $header
EMAIL;
// send mail
if($_POST){
mail($to, $subject, $message, $header);
echo $feedback;
}
?>
Remember very carefully, the part from Dear... to EMAIL has to be against the left side of the screen, without any tabs or spaces. Else it won't work!
Hopefully you can use this to your success :)

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.

Categories