2014-12-05 73 views
0

每當我嘗試發送PHP郵件時,它都會被縮短。我已經測試過要更改消息的內容,並且很明顯它與字符限制有關。PHP郵件神祕地縮短了

我已經找到了問題的原因,最近的是這個answer,說我應該添加新行\r\n,我有。

我在做什麼錯了?消息

內容:

$content .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
</head> 
<body>'; 

$content .= '<p>Welcome the latest update from our site!</p> '."\r\n\r\n"; 
$content .= 'We hope you enjoy this week\'s published articles: '."\r\n\r\n"; 
$content .= '<p style="font-size:15px;font-weight:bold;">'. $category[0]->cat_name .': <a href="'. get_permalink() .'">'. get_the_title() .'</a> <br><span style="font-weight:normal;"> '. get_the_excerpt() .'</span></p>'."\r\n\r\n"; 
$content .= '<p>Access all articles at: <a href="http://domain.com">http://domain.com</a></p> '."\r\n\r\n"; 
$content .= '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam at tincidunt lacus. Nulla non mi hendrerit, tincidunt eros id, rutrum nisl. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam vel libero risus. Vivamus vestibulum consectetur sapien.</p> '."\r\n\r\n"; 
$content .= '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam at tincidunt lacus. Nulla non mi hendrerit, tincidunt eros id, rutrum nisl. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam vel libero risus. Vivamus vestibulum consectetur sapien, eget blandit felis lobortis eu. Vivamus porttitor dui eget urna pellentesque</p>'."\r\n\r\n\r\n\r\n"; 
$content .= '</body></html>'; 

代碼來發送電子郵件:

function mail($recipient, $sender, $name, $subject, $message) { 

    $subject = stripslashes($subject); 
    $message = stripslashes($message); 

    $headers[] = "Content-Type: text/html; charset=ISO-8859-1"; 

    return wp_mail($recipient, $subject, $message, $headers); 
} 
+1

哪裏是你用實際的代碼發送電子郵件? – putvande 2014-12-05 16:58:16

+1

@putvande查看更新的問題。 – 2014-12-05 17:02:25

+3

也許'wp_mail'截斷你的消息? – putvande 2014-12-05 17:04:42

回答

0

您將添加頁眉的HTML。看功能mail

// To send HTML mail, the Content-type header must be set 
$headers ='MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; 

// Mail it 
mail($to, $subject, $content, $headers); 

,並刪除\ r \ n \ r \ n

+0

如果你看看我的問題,你會看到我已經設置標題爲「Content-Type:text/html; charset = ISO-8859-1」 – 2014-12-05 17:12:20