0

I have a contact form on my site with the following php script but when people compile the form e send a message from my site, I receive their message always in spam..

So if i'm not careful to check always my spam folder, i lost messages received from my site..

I don't know how to solve this problem.. thanks in advance!

<?php
include('SMTPClass.php');

$use_smtp = '0';
$emailto = 'antonycee@gmail.com';

// retrieve from parameters
$emailfrom = isset($_POST["email"]) ? $_POST["email"] : "";
$nocomment = isset($_POST["nocomment"]) ? $_POST["nocomment"] : "";
$subject = 'Email da festeprivateroma.com';
$message = '';
$response = '';
$response_fail = 'There was an error verifying your details.';

    // Honeypot captcha
    if($nocomment == '') {

        $params = $_POST;
        foreach ( $params as $key=>$value ){

            if(!($key == 'ip' || $key == 'emailsubject' || $key == 'url' || $key == 'emailto' || $key == 'nocomment' || $key == 'v_error' || $key == 'v_email')){

                $key = ucwords(str_replace("-", " ", $key));

                if ( gettype( $value ) == "array" ){
                    $message .= "$key: \n";
                    foreach ( $value as $two_dim_value )
                    $message .= "...$two_dim_value<br>";
                }else {
                    $message .= $value != '' ? "$key: $value\n" : '';
                }
            }
        }

    $response = sendEmail($subject, $message, $emailto, $emailfrom);

    } else {

        $response = $response_fail;

    }

echo $response;

// Run server-side validation
function sendEmail($subject, $content, $emailto, $emailfrom) {

$from = $emailfrom;
$response_sent = 'Grazie. Il tuo messaggio è stato ricevuto.';
$response_error = 'Error. Please try again.';
$subject =  filter($subject);
$url = "Origin Page: ".$_SERVER['HTTP_REFERER'];
$ip = "IP Address: ".$_SERVER["REMOTE_ADDR"];
$message = $content."\n$ip\r\n$url";

// Validate return email & inform admin
$emailto = filter($emailto);

// Setup final message
$body = wordwrap($message);

if($GLOBALS['use_smtp'] == '1'){

    $SmtpServer = 'SMTP SERVER';
    $SmtpPort = 'SMTP PORT';
    $SmtpUser = 'SMTP USER';
    $SmtpPass = 'SMTP PASSWORD';

    $to = $emailto;
    $SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);
    $SMTPChat = $SMTPMail->SendMail();
    $response = $SMTPChat ? $response_sent : $response_error;

} else {

    // Create header
    $headers = "From: $from\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/plain; charset=utf-8\r\n";
    $headers .= "Content-Transfer-Encoding: quoted-printable\r\n";

    // Send email
    $mail_sent = @mail($emailto, $subject, $body, $headers);
    $response = $mail_sent ? $response_sent : $response_error;

}
return $response;
}

// Remove any un-safe values to prevent email injection
function filter($value) {
$pattern = array("/\n/", "/\r/", "/content-type:/i", "/to:/i", "/from:/i", "/cc:/i");
$value = preg_replace($pattern, "", $value);
return $value;
}

exit;

?>
  • The problem is not that emails that i send go on spam.. but the email that i receive from the contact form on my site go on my spam folder.. i hope to be clear..! – Antonio C. Jan 04 '16 at 19:04
  • Your `$emailfrom` should be a valid email address on your server and you should use the submitted email as a "Reply-To:" header - you should find fewer emails get flagged as spam that way as your server has the right to use SMTP validly. Might also ba useful http://stackoverflow.com/questions/33948622/php-mail-function-server-and-localhost-not-working/33948920#33948920 – Steve Jan 04 '16 at 23:25

0 Answers0