2017-10-12 35 views
0

我使用PHP郵件功能發送一些HTML文本。嘗試使用PHP郵件功能對齊文本發送郵件

,使文本

$msg='<h1>This is the mail text i want to center</h1>'; 

然後我使用郵件功能,如:

mail($recipient,$subject,$msg,$mailheaders); 

我收到的電子郵件,但所有的文本左對齊。 我試圖用中心標記

$msg='<center><h1>This is the mail text i want to center</h1></center>'; 

但郵件永不熄滅(這是不允許的?)

還試圖用樣式屬性

$msg='<h1 style="text-align:center;">This is the mail text i want to center</h1>'; 

但同樣沒有運氣。 任何想法歡迎

+0

您需要指定它是發送頭中的html。另外你最好使用像phpmailer這樣的第三方庫來處理這個問題。 – Akintunde007

+0

@Akintunde「你需要指定它是發送頭文件中的html」我應該怎麼做? – xbass540

+0

顯示$ mailheaders變量 – Akintunde007

回答

1

它總是很難發送一個不錯的設計良好的郵件。

一個(舊)的方式是使用表,但它不是很好。現在你可以使用一些很好的第三方庫,比如phpmailer或其他。 由於提供程序不支持外部CSS,因此您需要應用內聯css。

檢查這篇文章https://www.formget.com/php-send-html-email-template/

+0

我設法使用郵件功能足夠的郵件風格,但我缺少一些基本的php屬性。我會嘗試這篇文章 – xbass540