2012-06-30 29 views
-2

這是我的註冊郵件示例,它向用戶發送電子郵件以激活其帳戶。顯示爲垃圾郵件的PHP郵件()

//send activation email 

$to  = $email; 
$subject = "Activate your account!"; 
$headers = "From: Example.com\r\n"; 
$headers .= "CC: $email\r\n"; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
$server = "http://www.example.com"; 

ini_set("SMTP", $server); 
$body = "<table style='border-top:1px solid #707070;border-bottom:1px solid #707070;margin-top:5px;'>"; 
$body .= "<tr><td colspan='2'><span style='font-family:arial;font-size:12px;color:#000000;'>Your login details are as follows; </span></td></tr>"; 
$body .= "<tr style='background-color:#f2f4f6;margin-bottom:5px;'><td>Username:</td><td>$username</td></tr>"; 
$body .= "<tr style='background-color:#f2f4f6;margin-bottom:5px;'><td>Password:</td><td>$password</td></tr></table>"; 
$body .= "<table><tr><td><span style='font-family:arial;font-size:12px;color:#000000;'>Follow the link:</span></td>"; 
$body .= "<td><a style='text-decoration:underline;font-family:arial;font-size:12px;color:#264971' href='http://www.example.com/activate.php?id=$lastid&code=$random'>http://www.example.com/activate.php?id=$lastid&code=$random</a></td>"; 
$body .= "</tr></table>"; 
$body .= "</body></html>"; 

//function to send email 

if (mail($to, $subject, $body, $headers)) {} 

當測試用戶註冊時,激活電子郵件結束在SPAM文件夾中。我必須改變以糾正此問題?

+0

你做了最初的研究嗎? –

+3

[爲什麼所有通過php的郵件發送的郵件轉到垃圾郵件框,但沒有直接從域的帳戶發送郵件?](http://stackoverflow.com/questions/2032286/why-are-all-mails - 通過phps郵件轉到垃圾郵箱 - 但不是郵件發送直接)和[PHP的郵件()直接發送到垃圾郵件框](http://stackoverflow.com/questions/) 2032552/php-mail-sending-straight-to-spam-box?rq = 1) – Leigh

+2

沒有日期標題,從標題無效(域而不是電子郵件) – Gryphius

回答

1

這SHD 工作

<? 
    $headers .= "Organization: Sender Organization\r\n"; 
    $headers .= "MIME-Version: 1.0\r\n"; 
    $headers .= "Content-type: text/plain; charset=iso-8859-1\r\n"; 
    $headers .= "X-Priority: 3\r\n"; 
    $headers .= "X-Mailer: PHP". phpversion() ."\r\n" 
?> 

here

0

這對我來說看起來完全正常。無數的原因表明您的電子郵件顯示爲垃圾郵件(通常與電子郵件服務器和客戶端的類型,收件人使用的垃圾郵件過濾引擎以及您的域/服務器的歷史活動有關)。

將認證的SMTP或IMAP服務器與可靠的提供程序(而不是匿名本地SMTP服務器)一起使用可能會有更好的結果(因爲它大概未知或被認爲對大多數大型Webmail提供程序不安全)。

(幾乎)永遠不會被標記爲垃圾郵件的唯一可靠方法是要求用戶將您添加到他們的白名單。

0

使用phpMailer smtp方法更簡單更好。 http://code.google.com/a/apache-extras.org/p/phpmailer/

或者您可以使用此代碼,可能會幫助您:

function email($to,$name,$subject,$message) 
{ 
    $content='<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
    <head> 
     <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
     <title>'.$subject.'</title> 
    </head> 
    <body> 
    '.$message.' 
    </body> 
    </html>'; 
    $smtp_server = "mailserver.domain.com"; 
    $port = 25; 
    $mydomain = "domain.com"; 
    $username = "[email protected]"; 
    $from = "From Name"; 
    $password = "myEmailPassword"; 
    $headers = "From: $from <[email protected]>\r\n"; 
    $headers .= "To: $name <$to>\r\n"; 
    $headers .= "Reply-To: [email protected]\r\n"; 
    $headers .= "MIME-Version: 1.0\r\n"; 
    $headers .= "Content-Type: text/html; charset=UTF-8\r\n"; 
    $handle = fsockopen($smtp_server,$port); 
    fputs($handle, "HELO $mydomain\r\n"); 
    fputs($handle, "AUTH LOGIN\r\n"); 
    fputs($handle, base64_encode($username)."\r\n"); 
    fputs($handle, base64_encode($password)."\r\n"); 
    fputs($handle, "MAIL FROM:<$username>\r\n"); 
    fputs($handle, "RCPT TO:<$to>\r\n"); 
    fputs($handle, "DATA\r\n"); 
    fputs($handle, "$headers \nSubject: $subject \n$content \r\n"); 
    fputs($handle, ".\r\n"); 
    fputs($handle, "QUIT\r\n"); 
}