使用phpmailer通过电子邮件在php中发送垃圾邮件

时间:2015-12-16 15:59:29

标签: php phpmailer

我正在使用phpmailer发送带有pdf附件的电子邮件,但它是垃圾邮件。我的电子邮件很简单,只有pdf附件。我在谷歌上尝试了一切,但不知道我错过了。以下是我的代码。

 $email_settings = ORMEmailSettings::order_by('id', 'desc')->limit(1)->first();
    $email_host = $email_settings->email_host;
    $email_username = $email_settings->email_username;
    $email_password = $email_settings->email_password;

    require_once APPPATH . DIRECTORY_SEPARATOR . 'controllers/admin/smtp/class.phpmailer.php';
    if ($eventTicketId != 9999) {
        $eventId = $this->events_model->getAttachment($eventTicketId[0]->event_id);
        $emailSubject = $eventId[0]->title;
    } else {
        $emailSubject = "Here come the normal subject";
    }
    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->SMTPAuth = 'true';
    $mail->SMTPSecure = 'tls';
    $mail->SMTPKeepAlive = true;
    $mail->Host = 'xxxx.xxmsrv.de';
    $mail->Port = 587;
    $mail->IsHTML(true);

    $mail->Username = "xxxxxxx@myplusmarketing.com";
    $mail->Password = "xxxxxxxx2014*";
    $mail->SingleTo = true;

    $mail->From = "xxxxxxxxxxx@myplusmarketing.com";
    $mail->FromName = "My Email";
    $mail->AddAddress('xxxxxxxx.de');
    if ($eventTicketId != 9999) {
        $filename = "MPM-event" . $eventId[0]->id . "_.pdf";
        $filelocation = $_SERVER['DOCUMENT_ROOT'] . '/eventDocs';
        $fileNL = $filelocation . "/" . $filename;
        $mail->AddAttachment($fileNL, $filename,  $encoding = 'base64', $type = 'application/pdf');
    }
    $mail->Subject = $emailSubject;
    $mail->Body = '<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body style="margin: 0; padding: 0; font-family: Arial; font-size: 14px;     line-height: 17px;">
</body>
</html>';

    if ($mail->send()) {
        echo 'if';
        exit;
    } else {
        echo 'else';
        exit;
    }

1 个答案:

答案 0 :(得分:3)

您的邮件进入垃圾邮件并不意味着您的代码失败 - 相反,它显然有效!问题是接收服务器不信任您的站点,因此它将传入的电子邮件标记为垃圾邮件,以便最终用户永远不会看到它。

解决方案可能不是基于代码的。相反,您应该为您的域添加SPF记录。只要您有一个有用的Web主机,这并不难做到。如果这是你第一次这样做,你应该考虑使用类似http://www.spfwizard.net的东西,它可以为你完成所有艰苦的工作。