How do I stop the Phantom Emails from my PHP code? - php

I'm currently using an html5 website with a contact form and a php action to receive contact emails. I've tried a few different codes in my php but non have stopped the blank emails from coming. I do have google analytics enables on my code but have blocked the crawler through robot.txt. Here is my code.
PHP CODE
<?php
foreach ($_GET as $Field=>$Value) {
if($Value != ''){
$body .= "$Field: $Value\n";
}
}
$name = trim(htmlentities($_GET['name'],ENT_QUOTES,'utf-8'));
$email = trim(htmlentities($_GET['email'],ENT_QUOTES,'utf-8'));
$phone = trim(htmlentities($_GET['phone'],ENT_QUOTES,'utf-8'));
$messages = trim(htmlentities($_REQUEST['messages'],ENT_QUOTES,'utf-8'));
if (strlen($name) == 0 )
{
echo "<script>window.location = 'http://www.mason372.org/error.html'</script>";
}
if (strlen($email) == 0 )
{
echo "<script>window.location = 'http://www.mason372.org/error.html'</script>";
}
$to = "junior.8791#gmail.com";
$message = "Name: ".$name;
$message.="\n\nEmail: ".$email;
$message.="\n\nPhone: ".$phone;
$message .= "\n\nMessage: ".$messages;
$headers = "From: $email";
$headers .="\nReply-To: $email";
$success = mail($to, $subject, $message, $headers);
if ($success) {
echo "<script>window.location = 'http://www.mason372.org/thankyou.html'</script>";
} else {
echo "<script>window.location = 'http://www.mason372.org/error.html'</script>";
}
?>
CONTACT FORM
<form action="email.php" method="post" id="form">
<div class="5grid">
<div class="row">
<div class="6u">
<input type="text" class="name" name="name" id="name" placeholder="Name" value="" aria-describedby="name-format" required aria-required=”true” pattern="[A-Za-z-0-9]+\s[A-Za-z-'0-9]+" title="e.g.'John Doe'" required="" />
</div>
<div class="6u">
<input type="email" class="email" name="email" id="email" placeholder="Email" required="" />
</div>
</div>
<div class="row">
<div class="12u">
<input type="tel" class="tel" name="phone" id="phone" name="phone" type="text" placeholder="Phone Number" pattern="(?:\(\d{3}\)|\d{3})[- ]?\d{3}[- ]?\d{4}" required />
</div>
</div>
<div class="row">
<div class="12u">
<textarea name="messages" id="messages" placeholder="Message"></textarea>
</div>
</div>
<div class="row">
<div class="12u">
<input type="submit" class="button" value="Send Message">
<input type="reset" class="button button-alt" value="Clear Form">

Related

Print the value of datepicker and send it to my email

Hi I have the same issue. Just want to print out the value that was selected on the calendar and include it to send to my email. It prints out to the page but it does not include to the email.
PHP code:
<?php
if (isset($_POST['send'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$subject = "Attendance Form";
$date = $_POST['date[]'];
$message = "Bro./Sis. ".$name." "."attendance will be at"." ".print_r(date($date['d,m,Y']));
$emailTo = "me#domain.com";
$mailHeaders = "From: " . $name . "<". $email .">\r\n";
if (mail($emailTo, $subject, $date, $mailHeaders)) {
$message ='<div class="alert alert-success d-inline-block" role="alert">Your message has been sent.</div>';
$type = "success";
} else {
$error = '<div class="alert alert-danger d-inline-block" role="alert">Something went wrong, please try again.</div>';
}
}
?>
Hi guys thank you for your comments. I used the datepicker but whenever I use the jqueryui i cannot pick the value so i put the date as a type. This is my HTML:
<div class="container-fluid text-center" id="attendform" style="top: 50%;transform: translateY(25%) !important;position: relative;">
<!--Form for join us-->
<div class="container bg-light p-5 mt-5 d-inline-block text-center">
<h2 class="join-title text-center display-4 mb-0">Join us!</h2><br><br>
<div class="mt-0 mb-3" id="error"><? echo $error.$message; ?></div>
<div class="container text-center">
<form class="" method="post">
<label for="name" class="text-dark border-top-0 border-right-0 border-left-0" >Name: </label> <br>
<input class="form-control" type="text" name="name" id="name" placeholder="Bro./Sis."><br>
<label for="email">Email</label>
<input type="email" name="email" class="form-control" id="email" placeholder="user#domain.com" required> <br>
<!---->
<label for="date" class="d-inline-block">Date: </label>
<input type="date" id="datepicker" name="date[]" class="form-control" value=""></input><br>
<input class="btn btn-dark" id="sendbtn" type="submit" name="send" value="Send">
</form>
</div>
</div>
</div>
</div>
I disable the jquery datepicker first and try with the normal calendar
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<!--script-->
<script src="js/jquery-3.4.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js" integrity="sha256-0YPKAwZP7Mp3ALMRVB2i8GXeEndvCq3eSl/WsAl1Ryk=" crossorigin="anonymous"></script>
<!-- <script type="text/javascript">
$(function() {
$("#datepicker").datepicker();
});
</script> -->
I finally figure the answer:
PHP code
<?php
if (isset($_POST['send'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$subject = "Attendance Form";
$date = $_POST['date'];
$member = $_POST['member'];
$message = "Bro./Sis. ".$name." "."($member)"."\n\n"."Schedule:"." "."($date)";
$emailTo = "me#domain.com";
$mailHeaders = "From: " . $name . "<". $email .">\r\n";
if (mail($emailTo, $subject, $message, $mailHeaders)) {
$message ='<div class="alert alert-success d-inline-block" role="alert">Your message has been sent.</div>';
$type = "success";
} else {
$error = '<div class="alert alert-danger d-inline-block" role="alert">Something went wrong, please try again.</div>';
}
}
?>
I edited my form and put the jquery datepicker
<form class="" method="post">
<label for="name" class="text-dark border-top-0 border-right-0 border-left-0" >Name: </label> <br>
<input class="form-control" type="text" name="name" id="name" placeholder="Bro./Sis."><br>
<label for="email">Email</label>
<input type="email" name="email" class="form-control" id="email" placeholder="user#domain.com" required> <br>
<!---->
<label for="date" class="d-inline-block">Date: </label>
<input type="text" id="datepicker" name="date" class="form-control" value=""></input><br>
<p>Are you already a member of the youth?</p>
<label for=member>
<input type="radio" name="member" value="Yes member">Yes
<input type="radio" name="member" value="Non member">No
</select><br><br>
<input class="btn btn-dark" id="sendbtn" type="submit" name="send" value="Send">
</form>

My Form built in HTML5 and PHP is returning a white space

I am having issues with my form built is HTML and PHP. It is returning a white page after I clicked to submit. The website is online already http://diegodiasp.com/
The html is the following:
<form class="bg-light p-4 p-md-5 contact-form" action="./contactform.php" method="POST" >
<div class="form-group">
<input class="form-control" name="name" placeholder="Your Name">
</div>
<div class="form-group">
<input class="form-control" name="mail" placeholder="Your Email">
</div>
<div class="form-group">
<textarea class="form-control" name="message" cols="30" rows="7" placeholder="Message"></textarea>
</div>
<div class="form-group">
<input type="submit" value="Send Message" class="btn btn-primary py-3 px-5">
</div>
</form>
And the PHP is as bellow:
<?php
if(isset($_POST['email']) && !empty($_POST['email'])){
$name = addslashes($_POST['name']);
$email = addslashes($_POST['mail']);
$message = addslashes($_POST['message']);
$to = "info#diegodiasp.com";
$subject = "Contact - Diego Dias Front End";
$body = "Name: ".$name."\r\n".
"Email: ".$email."\r\n".
"Message: ".$message;
$header = "From:info#diegodiasp.com"."\r\n"."Reply-To:".$email."\r\n"."X=Mailer:PHP/".phpversion();
if(mail($to,$subject,$body,$header)){
echo("Email succesfully sent!");
}else{
echo("Email not sent!");
}
}
?>
The textbox for the email address is called mail.
You are checking if 'email' isset and not 'mail'.
Correct your php to the following:
if(isset($_POST['mail']) && !empty($_POST['mail'])){

Not receiving emails on form submit

I have designed an email for a cart page in this website. When checkout is clicked nothing happens. Instead it displays an empty page with a different header.
PHP:
<?php
$subject = "An order has been placed on your website";
if (isset($_POST['button '])) {
$firstName = $_POST['first-name'];
$lastName = $_POST['last-name'];
$mailFrom = $_POST['email'];
$address = $_POST['address'];
$productName = $_POST['product-name'];
$quantity = $_POST['quantity'];
$phone = $_POST['tel'];
$mailTo = "admin#onlineooty.co.in";
$headers = "From: ".$mailFrom;
$txt = "you have recieved a mail from ".$firstName.".\n\n"."whose address is : ".$address.".\n\n"."the product name is: ".$productName."\n\n"."the phone number is: ".$phone;
mail($mailTo, $subject, $txt, $headers );
header("Location: cart.php?mailsend");
}
?>
My form:
<form class="emailForm" action="email.php" method="post">
<div class="input-checkbox">
<div class="caption">
<div class="form-group">
<input class="input" type="text" name="first-name" placeholder="First Name">
</div>
<div class="form-group">
<input class="input" type="text" name="last-name" placeholder="Last Name">
</div>
<div class="form-group">
<input class="input" type="email" name="email" placeholder="Email">
</div>
<div class="form-group">
<input class="input" type="text" name="address" placeholder="Address">
</div>
<div class="form-group">
<input class="input" type="text" name="product-name" placeholder=" product required">
</div>
<div class="form-group">
<input class="input" type="number" name="quantity" placeholder="quantity in kgs" max="10">
</div>
<div class="form-group">
<input class="input" type="text" name="pin-code" placeholder="Pin Code">
</div>
<div class="form-group">
<input class="input" type="tel" name="tel" placeholder="phone">
</div>
</div>
</div>
</div>
<div class="payment-method">
<span>Kindly proceed with the payment to get order confirmation <font color="red">*No refund provided after order confirmation*</font></span>
<div class="input-radio">
<label for="payment-2">
<span>We do accept payments only on Google Pay as of now.
</span>
Google Pay
</label>
<div class="caption">
<p>We do accept payments on <font color = "blue">GPay
</font>, you can pay us on this number <strong>123456789
</strong>.
</p>
</div>
</div>
<button class="submit-button" type="submit" name="button">Checkout
</button>
</form>
Remove the space, your code should be like this:
<?php
$subject = "An order has been placed on your website";
if (isset($_POST['button'])){
$firstName = $_POST['first-name'];
$lastName = $_POST['last-name'];
$mailFrom = $_POST['email'];
$address = $_POST['address'];
$productName = $_POST['product-name'];
$quantity = $_POST['quantity'];
$phone = $_POST['tel'];
$mailTo = "admin#onlineooty.co.in";
$headers = "From: ".$mailFrom;
$txt = "you have recieved a mail from ".$firstName.".\n\n"."whose address is : ".$address.".\n\n"."the product name is: ".$productName."\n\n"."the phone number is: ".$phone;
mail($mailTo, $subject, $txt, $headers );
header("Location: cart.php?mailsend");
}

PHP contact form will not submit

I have a simple php contact form i got from a web tutorial. It worked yesterday, but will not work today. I'd love some help, as I don;t know much php.
php:
<?php
//If the form is submitted
if(isset($_POST['submit'])) {
//Check to make sure that the name field is not empty
if(trim($_POST['contactname']) == '') {
$hasError = true;
} else {
$name = trim($_POST['contactname']);
}
//Check to make sure that the subject field is not empty
if(trim($_POST['subject']) == '') {
$hasError = true;
} else {
$subject = trim($_POST['subject']);
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$hasError = true;
} else if (!filter_var( trim($_POST['email'], FILTER_VALIDATE_EMAIL ))) {
$hasError = true;
} else {
$email = trim($_POST['email']);
}
//Check to make sure comments were entered
if(trim($_POST['message']) == '') {
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['message']));
} else {
$comments = trim($_POST['message']);
}
}
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = 'person#domain.com'; // Put your own email address here
$body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";
$headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
?>
HTML:
<form role="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform">
<?php if(isset($hasError)) { //If errors are found ?>
<p class="alert alert-danger">Please check if you've filled all the fields with valid information and try again. Thank you.</p>
<?php } ?>
<?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?>
<div class="alert alert-success">
<p><strong>Message Successfully Sent!</strong></p>
<p>Thank you for using our contact form, <strong><?php echo $name;?></strong>! Your email was successfully sent and we’ll be in touch with you soon.</p>
</div>
<?php } ?>
<div class="form-group">
<label for="name">Your Name<span class="help-required">*</span></label>
<input type="text" name="contactname" id="contactname" value="" class="form-control required" role="input" aria-required="true" />
</div>
<div class="form-group">
<label for="email">Your Email<span class="help-required">*</span></label>
<input type="text" name="email" id="email" value="" class="form-control required email" role="input" aria-required="true" />
</div>
<div class="form-group">
<label for="subject">Subject<span class="help-required">*</span></label>
<input type="text" name="email" id="subject" class="form-control required" role="input" aria-required="true">
</div>
<div class="form-group">
<label for="message">Message<span class="help-required">*</span></label>
<textarea rows="8" name="message" id="message" class="form-control required" role="textbox" aria-required="true"></textarea>
</div>
<div class="actions">
<input type="submit" value="Send Your Message" name="submit" id="submitButton" class="btn btn-grey" title="Click here to submit your message!" />
<input type="reset" value="Clear Form" class="btn btn-grey pull-right" title="Remove all the data from the form." />
</div>
</form>
It gets hung up on the validation. Not sure why.
$_POST["subject] is not defined in your form. Your SUBJECT field is called EMAIL:
Change:
<div class="form-group">
<label for="subject">Subject<span class="help-required">*</span></label>
<input type="text" name="email" id="subject" class="form-control required" role="input" aria-required="true">
</div>
With:
<div class="form-group">
<label for="subject">Subject<span class="help-required">*</span></label>
<input type="text" name="subject" id="subject" class="form-control required" role="input" aria-required="true">
</div>

How to make a send yourself a copy check box

I need a check box that can send yourself a copy. For example, they've filled out the contact form and want a copy sent to their self, they check the box and it will email it to me and still email it to them. Here's my PHP:
//If the form is submitted
if(isset($_POST['submit'])) {
//Check to make sure that the name field is not empty
if(trim($_POST['contactname']) == '') {
$hasError = true;
} else {
$name = trim($_POST['contactname']);
}
//Check to make sure that the subject field is not empty
if(trim($_POST['subject']) == '') {
$hasError = true;
} else {
$subject = trim($_POST['subject']);
}
//Check to make sure that the subject field is not empty
if(trim($_POST['weburl']) == '') {
$site = trim($_POST['weburl']);
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+#[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
$hasError = true;
} else {
$email = trim($_POST['email']);
}
//Check to make sure comments were entered
if(trim($_POST['message']) == '') {
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['message']));
} else {
$comments = trim($_POST['message']);
}
}
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = 'myemail#domain.com'; // Put your own email address here
$body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nSite: \n\nComments:\n $comments";
$headers = 'From: BTSyncrets Contact <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
Here's my contact form code:
<div id="contact" class="offset4 login">
<form style="margin-top: 5% !important;" method="post" action="index.php" id="contactform">
<fieldset class="well">
<br>
<div class="clearfix">
<label for="name">
Your Name<span class="help-required">*</span>
</label>
<div class="input">
<input type="text" id="boxblack" name="contactname" id="contactname" value="" class="span6 required" role="input" aria-required="true" />
</div>
</div>
<div class="clearfix">
<label for="email">
Your Email<span class="help-required">*</span>
</label>
<div class="input">
<input type="text" id="boxblack" name="email" id="email" value="" class="span6 required email" role="input" aria-required="true" />
</div>
</div>
<div class="clearfix">
<label for="weburl">
Your Website
</label>
<div class="input">
<input type="text" id="boxblack" name="weburl" id="weburl" value="" class="span6 required url" role="input" aria-required="true" />
</div>
</div>
<div class="clearfix">
<label for="subject">
Subject<span class="help-required">*</span>
</label>
<div class="input">
<select name="subject" id="boxblack" id="subject" class="span6 required" role="select" aria-required="true">
<option></option>
<option>One</option>
<option>Two</option>
</select>
</div>
</div>
<div class="clearfix">
<label for="message">Message<span class="help-required">*</span></label>
<div class="input">
<textarea rows="8" id="boxblack" style="resize: none;" name="message" id="message" class="span6 required" role="textbox" aria-required="true"></textarea>
</div>
</div>
<label class="checkbox">
<input type="checkbox" name="copy" value="1" /> Send Yourself a copy
</label>
<div class="actions">
<input type="submit" value="Send Your Message" name="submit" id="submitButton" class="btn btn-inverse" title="Click here to submit your message!" />
<input type="reset" value="Clear Form" class="btn btn-danger" title="Remove all the data from the form." />
</div>
</fieldset>
</form>
</div><!-- form -->
See the Add this comment below.
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = 'myemail#domain.com'; // Put your own email address here
$body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nSite: \n\nComments:\n $comments";
$headers = 'From: BTSyncrets Contact <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
// Add this
if (isset($_POST['copy'])) {
$headers .= "\nBcc: myemailaddress#example.com";
}
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}

Categories