在phpmailer脚本中实现Regex以防止发送垃圾邮件

时间:2018-01-26 15:09:04

标签: php regex input phpmailer spam-prevention

我是网页设计师,我不知道php是如何工作的。 我正在处理的网站是在smtp服务器上,表单需要主机地址,用户名和密码来发送电子邮件,所以我找到并修改了这个脚本供我使用。

这是我的问题: 我需要在下面的脚本上使用Regex来防止垃圾邮件;正如我所说,我根本不知道php,我尝试的一切都出错了。

你能帮帮我吗?谢谢:)

<?php

require("class.phpmailer.php");





$name = $_POST["firstName"];

$email = $_POST["email"];

$object = $_POST["oggetto"];

$message = $_POST["message"];



$nomemittente = $name . ' ' . $email;





$messaggio = "<div style=\"font-family:Verdana, Arial, Helvetica, sans-serif; font-size: 14px; color: #000000;\"><br>

<strong>Nome:</strong> " . $name . "<br>

<strong>Object:</strong> " . $object . "<br>

<strong>E-mail:</strong> " . $email . "<br><br>

<strong>Testo:</strong> "  . $testo . "<br><br>

</div>";



$mail = new PHPMailer();



$mail->IsSMTP(); 

// L'host remoto con cui spediremo, nel caso di gmail è smtp.gmail.com

$mail->Host = "xxx.xxxx.it";

$mail->SMTPAuth = true;



// Specifichiamo che vogliamo spedire tramite ssl, se non volete basta eliminae queste due righe

/*$mail->SMTPSecure = 'ssl';

$mail->Port = 465;
*/



$mail->Username = "xxxxxxxxx";

$mail->Password = "xxxxx";


$mail->SMTPDebug = 1;



$mail->From = "$email";

$mail->FromName = "$name";



// Qui inseriamo l'indirizzo a cui recapitare le email spedite tramite il form

$mail->AddAddress("xxxxxxxxx@xx.com");



$mail->AddReplyTo("$email", "$nome");





$mail->WordWrap = 50; 



$mail->IsHTML(true);



$mail->Subject = "$nomemittente - Requested informations";

$mail->Body    = "$messaggio</b>";



    if($mail->Send()){

        echo "<script type='text/javascript'>alert('Message sent!')</script>";
    echo "<script>setTimeout(\"location.href = 'index.html';\",400);</script>"; 

    }else{


        echo "<script type='text/javascript'>alert('Something goes wrong!)</script>";
    echo "<script>setTimeout(\"location.href = 'index.html';\",400);</script>";
    } 


?>

0 个答案:

没有答案