Search code examples
phphtmlvalidationemailspoofing

my website contact form being used to send spoof emails


My hosting provider has contacted me and said one of the sites I have designed is sending spoof emails. Done a little bit of research but I still don't really understand how/what are they are doing to send these spoof emails. However more importantly how should I approach this, would it help if I try and put one of these 'captcha' things in place on the contact form or should I change the code I have on my site. Which is shown below:

<?php

$EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); 
$EmailTo = "***";
$Subject = "Message to A R C Products";
$Name = Trim(stripslashes($_POST['Name'])); 
$Address = Trim(stripslashes($_POST['Address'])); 
$Telephone = Trim(stripslashes($_POST['Telephone'])); 
$Message = Trim(stripslashes($_POST['Message'])); 



// prepare email body text


$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$Message = "
Name:$Name 
Address: $Address 
Telephone: $Telephone 
$Message";

// send email
$success = mail($EmailTo, $Subject, $Message, $headers);

// redirect to success page
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
?>


<h2><strong>Contact Us</strong></h2>
                      <form method="POST" action="contact.php">
                      <br/>
            <p style="margin-top: 0;">Fields marked (*) are required</p>

            <p style="margin-top: 0;">Your Email:* <br/>
            <input type="text" name="EmailFrom">
            <p style="margin-top: 0;">Name:* <br/>
            <input type="text" name="Name">
            <p style="margin-top: 0;">Address:<br/>
            <input type="text" name="Address">
            <p style="margin-top: 0;">Telephone:<br/>
            <input type="text" name="Telephone">
            <p style="margin-top: 0;">Message:*<br/>
            <TEXTAREA NAME="Message" ROWS=6 COLS=40>
            </TEXTAREA>
            <p style="margin-top: 0;"><input type="submit" name="submit" value="Submit">

            </form>

Solution

  • Take a look on filter_input to clean your input data. Also i would not use the email from the form as a from address.

    $EmailFrom = filter_input(INPUT_POST,'EmailFrom', FILTER_SANITIZE_EMAIL);