簡體   English   中英

使用phpmailer通過電子郵件在php中發送垃圾郵件

[英]Email going into spam in php using 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;
    }

您的郵件發送到垃圾郵件並不意味着您的代碼失敗 - 相反,它顯然有效! 問題是接收服務器不信任您的站點,因此它將傳入的電子郵件標記為垃圾郵件,以便最終用戶永遠不會看到它。

解決方案可能不是基於代碼的。 相反,您應該為您的域添加SPF記錄。 只要您有一個有用的Web主機,這並不難做到。 如果這是你第一次這樣做,你應該考慮使用像http://www.spfwizard.net這樣的東西,它可以為你完成所有艱苦的工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM