PHP form sending blank emails every day

Hi all,
I am new to PHP and I have built one php form using php mailer. But everyday my mailbox is full with blank email from this form. Kindly help to solve it as i have been struggling for a long time to resolve this issue.



$to = "";		
$multipleemail = array($to);
$msgSend = stripslashes(nl2br($message));			
$noreply = "";								
$mail = new PHPMailer(); // defaults to using php "mail()"								
//$body             = file_get_contents('contents.html');					
$mailbody =
     >     > "<table width='700px' cellpadding='2' border='1' cellspacing='0' cellspacing='0' style='font-size:14px; font-family:Helvetica, sans-serif; border:1px solid #526a6d;'>
    >     >  <tr><td align='left' colspan='2'style='padding-left:10px;font-size:14px; background:#526a6d; color:#ffffff; font-family:Helvetica, sans-serif; font-weight:bold; padding:5px'>Enquiry Details</td></tr>  
    >     >  <tr><td width='30%' align='left'  style='padding-left:10px'><b>Full Name:</b></td><td align='left'>$name </td></tr>
    >     >  <tr><td width='30%' align='left'  style='padding-left:10px'><b>Current Designation:</b></td><td align='left'>$designation </td></tr>
    >     >  <tr><td align='left' style='padding-left:10px'><b>Company:</b></td><td align='left'>$company </td></tr>
    >     >  <tr><td align='left' style='padding-left:10px'><b>Email:</b></td><td align='left'>$email </td></tr>
    >     >  <tr><td align='left' style='padding-left:10px'><b>Phone:</b></td><td align='left'> $phone</td></tr>
    >     >  <tr><td align='left' style='padding-left:10px'><b>Message:</b></td><td align='left'> $description</td></tr>				  			   
    >     >  </table>";									
$mail->SetFrom($noreply, "riviere")					
foreach($multipleemail as $val) {					
$mail->AddAddress($val, 'riviere');								
$mail->Subject    = "Enquiry from website";
$mail->AltBody    = "Enquiry from website"; // Alt Body									
$mail->Body = $mailbody;
if (isset($_FILES['file_attach']) &&
$_FILES['file_attach']['error'] == UPLOAD_ERR_OK) {
/********************************User Rply*****************************************/
$mail1 = new PHPMailer();
$multipleemail = array($email);																				
$mailbody = "<html><head><title>This is your HTML email!</title></head><body style='top left repeat-x; text-align:left;'><div style='background:#526a6d;width:700px; font-family:Georgia; font-size:14px; color:#fff; text-align:left; padding:30px;'>Dear ".$name.",Thanks for reaching out. I will get in touch with you shortly.</div></body></html>";					
$mail1->SetFrom($noreply, "riviere");								
foreach($multipleemail as $val) {
$mail1->AddAddress($val, 'riviere');								
$mail1->Subject    = "Thank you for contacting me";							
$mail1->AltBody    = "Thank you for contacting me"; // Alt Body	
$mail1->Body = $mailbody;
if(!$mail1->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
}// End Php mailer
/*echo '<script language="javascript">';
echo 'window.location="contact.php?mess=successful"';
echo '</script>';*/
<?php include 'header.php';?>


>  <form id="" action="" enctype="multipart/form-data" class="git_form get_in_touch_form form-horizontal" onSubmit="return validate()" method="POST">
> <input type="hidden" name="retURL" value="thank-you.php">

      <div class="form-group">
       <input type="text" class="form-control form-effect" id="name" name="name" 
        oninvalid="setCustomValidity('Please enter valid name')"
       placeholder="Full Name" required>
      <div class="form-group">
       <input type="text" class="form-control form-effect" id="designation" name="designation" placeholder="Current Designation">
    <div class="form-group">
       <input type="text" class="form-control form-effect" id="company" name="company" placeholder="Company">
    <div class="form-group">                                 
  	   <input type="email" class="form-control form-effect" id="email" name="email" pattern="[^ @]*@[^ @]*" placeholder="Email" required>
    <div class="form-group">                                 
       <input type="text" class="form-control form-effect" id="phone" name="phone" placeholder="Telephone">
    <div class="form-group">
      <textarea type="textarea" class="form-control form-effect" id="description" name="description"placeholder="Message"></textarea>
    <button type="submit" class="btn center-block" id="submit" name="submit" required>Send</button>

Have you tried sending yourself a message? A blank email could be someone trying to break your script.

If you get blank emails when you send yourself a message it might be worth trying plain text messages first as they’re easier to follow.

It may be a good idea to validate the form data to make sure that everything has been filled in properly before the mail can be sent.

1 Like

Thanks for your reply but i dont want all the fields mandatory.
when anyone fill up a form i get data in proper table format. as i want it.
otherwise everyday i get blank emails desired format but empty

no one has suggested that you do that.

1 Like

Please checkout the below script -


/* These are the variable that tell the subject of the email and where the email will be sent.*/

$emailSubject = 'Customer Has a Question!';
$mailto = '';

/* These will gather what the user has typed into the fieled. */

$nameField = $_POST['name'];
$emailField = $_POST['email'];
$questionField = $_POST['question'];

/* This takes the information and lines it up the way you want it to be sent in the email. */

$body = <<<EOD
Name: $name <br>
Email: $email <br>
Question: $question <br>

$headers = "From: $email\r\n"; // This takes the email and displays it as who this email is from.
$headers .= "Content-type: text/html\r\n"; // This tells the server to turn the coding into the text.
$success = mail($mailto, $emailSubject, $body, $headers); // This tells the server what to send.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form Mailer</title>

<form id="form1" name="form1" method="post" action="form_mailer.php">
<table width="455" border="0" cellspacing="0" cellpadding="0">
    <td width="175" height="44" align="center"><label for"name">name</label></td>
    <td width="280"><input name="name" type="text" id="name" size="30" />
    <td height="45" align="center"><label for="email">email</label></td>
    <td><input name="email" type="text" id="email" size="30" /></td>
    <td height="41" align="center"><label for="question">question</label></td>
    <td><textarea name="question" cols="30" rows="5" id="question"></textarea></td>
    <td height="38">&nbsp;</td>
      <input type="submit" name="Submit" id="Submit" value="Submit" />


those statements are unnecessary - copying values from one field to another achieves nothing unless you also validate or sanitise it at the same time (and then can tell by which name is referenced as to whether the field is definitely valid or has yet to be validated).

If you are not going to validate the inputs then it is better to use the $_POST values in the assignment to $body as then it is at least ovious that the fields can contain anything.

But you clearly want some to be mandatory, or else you would be happy to receive blank emails.
You don’t have to make them all mandatory, but as things stand there is no back-end validation, so you will continue to get blank forms.
Any front-end validation cannot be relied upon, as older browsers don’t recognise the required attribute or all input types. Java script may be disabled, and anything front-end can be manipulated, changed or bypassed by a malicious user.
Therefore any front-end validation should be backed up by back-end validation.

Looking at your input attributes, only “email” is required, which implies you are happy for the others to be left blank.
Luckily for you, php has a function to validate that for you, see filter_var and FILTER_VALIDATE_EMAIL as its filter type.

if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { $valerrors[] = "The Email address you supplied is invalid." ; }

If you want to check any of the text fields are blank, something like this would work

if(!str_ireplace(' ','',$name)) { $valerrors[] = "You did not fill in the name field." ; }

This will be true if the field is blank or contains nothing but spaces.
You can later check if the array $valerrors is set, if it is, send them back to the form and you may echo out the array as a list. If the array is not set, send the mail.
There may be other ways and other considerations like sanitisation, but it’s a simple method of ensuring that emails don’t get sent without input in the required fields.

So should i use POST instead of REQUEST??

thanks i will try this.

To test if the form has been submitted use:


then validate all the inputs and copy the valid values to different names (but only if they are valid).


if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
   $email = $_POST['email'];
} else {
   // code for invalid email goes here
   $email = '';
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.