如何使用PHPMailer欺骗来自地址的电子邮件?

时间:2015-08-02 02:58:07

标签: php email smtp phpmailer

我对做任何恶意事情都不感兴趣,这纯粹是出于教学原因。

我读了这个帖子:http://lifehacker.com/how-spammers-spoof-your-email-address-and-how-to-prote-1579478914

在评论中你可以看到一个人欺骗为mz@fb.com。我想知道他是怎么做到的。

我已经让PHPMailer使用我的Gmail帐户,但它忽略了我提供的地址并使用我的Gmail帐户。

有诀窍吗?我需要一个smtp服务器吗?我有hostgator ......

这是我的代码:

function SendMail( $ToEmail, $FromEmail, $FromName, $Subject, $MessageTEXT, $isHTML, $MessageHTML ) {
        require_once("libphp-phpmailer/class.phpmailer.php");// Add the path as appropriate
        $Mail = new PHPMailer();
        $Mail->IsSMTP(); // Use SMTP
        $Mail->Host        = "smtp.gmail.com"; // Sets SMTP server
        $Mail->SMTPDebug   = 2; // 2 to enable SMTP debug information
        $Mail->SMTPAuth    = TRUE; // enable SMTP authentication
        $Mail->SMTPSecure  = "tls"; //Secure conection
        $Mail->Port        = 587; // set the SMTP port
        $Mail->Username    = 'EMAIL@gmail.com'; // SMTP account username
        $Mail->Password    = 'PASSWORD'; // SMTP account password
        $Mail->Priority    = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
        $Mail->CharSet     = 'UTF-8';
        $Mail->Encoding    = '8bit';
        $Mail->Subject     = $Subject;
        $Mail->ContentType = 'text/html; charset=utf-8\r\n';
        $Mail->From        = $FromEmail; 
        $Mail->FromName    = $FromName;
        $Mail->WordWrap    = 900; // RFC 2822 Compliant for Max 998 characters per line

        $Mail->AddAddress( $ToEmail ); // To:
        $Mail->isHTML( $isHTML );
        if ( $isHTML ){
            $Mail->Body    = $MessageHTML;
            $Mail->AltBody = $MessageTEXT; 
        }
        else{
            $Mail->Body    = $MessageTEXT;
            $Mail->AltBody = $MessageHTML;  
        }
        $Mail->Send();
        $Mail->SmtpClose();

        if ( $Mail->IsError() ) { // ADDED - This error checking was missing
            return FALSE;
        }
        else {
            return TRUE;
        }
    }

0 个答案:

没有答案