我正在使用phpmailer發送帶有pdf附件的電子郵件,但它發送垃圾郵件。我的電子郵件很簡單,只需要pdf附件。我試過谷歌上的所有內容,但不知道我錯過了。以下是我的代碼。在php中使用phpmailer進入垃圾郵件的電子郵件
$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 = "[email protected]marketing.com";
$mail->Password = "xxxxxxxx2014*";
$mail->SingleTo = true;
$mail->From = "[email protected]";
$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;
}
'$ mail-> SMTPAuth ='true';'應該是'$ mail-> SMTPAuth = true;'你不需要設置SingleTo,因爲你只是發送到一個地址。看起來您已經將代碼基於一個過時的示例,因此請確保您正在運行最新的PHPMailer。 – Synchro