2013-09-23 63 views
1

我正在PHP中開發一個網站,並希望在用戶註冊時向用戶發送電子郵件。css在使用AWS發送電子郵件時不起作用

我能夠成功地做到這一點。 即使我使用html格式,它以html格式發送。

我試過了。我知道圖片應該上傳到服務器,但我會稍後再做。

$bodyPart = ' 
<body style="background-color:#FFFFFF;"> 

<img id="header" style="position:absolute; left:85px; top:50px; " src="images/logo.jpg" width="140" height="90" border="0" alt="" /></a> 


<img id="cloths" style="position:absolute; left:275px; top:25px;" src="images/cloths.jpg" width="350" height="300" border="0" alt="" /></a> 

<font size="7" style="font-family:Times new Roman; position:absolute; left:50px; top:120px;">Thank YOU</font> 

<font size="3" style="font-family:Times new Roman;position:absolute;left:50px; top:165px;">For registering with our team </font> 

<img id="bag" style ="position:absolute; left:290px; top:345px;"src="images/bag1.jpg" width="250" height="240" border="0" alt="" /></a> 

<img style="position:absolute; left:30px; top:440px; "id="watch" src="images/watch1.jpg" width="260" height="180" border="0" alt="" /></a> 

</body> 

'; 

    $m->setMessageFromString($plainTextBody,$bodyPart); 

    print_r($ses->sendEmail($m)); 

我應該得到這個輸出

enter image description here

但我得到這個代替。

enter image description here

但問題是格式化,即使它在我的本地作品作爲一個獨立的文件沒有正確完成。我試圖使用外部CSS,內部CSS和內聯CSS。但它不起作用。

使用html發送電子郵件的CSS的任何示例都將非常有幫助。

謝謝提前。

+0

看到更新的問題。 – keen

+0

我們不知道setMessageFromString()和sendEmail()在做什麼... –

+0

setMessageFromString用於設置電子郵件正文部分,其中sendEmail用於在設置message,sendTo,from和subject部分之後發送電子郵件。 – keen

回答

1

修訂 正如我認爲,你剛纔做下面的代碼複製paste.Try。學習HTML基本語法。

不要忘記給予好評&標記爲解答;)

$bodyPart = ' 

<BODY 
<!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" /> 
<title>Untitled Document</title> 
</head> 

<body style="margin-top:20px;"> 
<table width="600" cellpadding="0" cellspacing="0" align="center"> 


<tr> 
    <td> 
    <img id="header" src="images/logo.jpg" width="140" height="90" border="0" alt="" /></a> 
    </td> 
    <td> 
    <img id="cloths" src="images/cloths.jpg" width="350" height="300" border="0" alt="" /></a> 
    </td> 
</tr> 

<tr> 
    <td> 
    <font size="7" style="font-family:Times new Roman;">Thank YOU</font> 
    </td> 
    <td> 
    <font size="3" style="font-family:Times new Roman;">For registering with our team </font> 
    </td> 
</tr> 
<tr> 
    <td> 
    <img id="bag" src="images/bag1.jpg" width="250" height="240" border="0" alt="" /></a> 
    </td> 
    <td> 
    <img id="watch" src="images/watch1.jpg" width="260" height="180" border="0" alt="" /></a> 
    </td> 
    </tr> 
</table>'; 

echo $bodyPart; 

較舊 使簡單。把一張桌子放在你的html身上&固定寬度。

你的電子郵件正文應像下面

$body = <<<BODY 
<!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" /> 
<title>Untitled Document</title> 
</head> 

<body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0" marginwidth="0" marginheight="0"> 
<table width="600" cellpadding="0" cellspacing="0" align="center"> 
<tr> 
<td>=============Your content =========</td> 
</tr> 
</table> 
BODY; 

echo $body; 
+0

它改變了輸出,但仍然沒有得到正確的格式,因爲它應該基於CSS。 – keen

+0

請注意,任何電子郵件客戶端都不會處理外部css/js。 您必須僅設置內聯css。 只需使用簡單的表格創建輸出。它適用於所有人。 可能是您的內嵌css –

+0

一些問題我使用內嵌的CSS,它作爲獨立的文件,但不是在發送電子郵件。 – keen

0

安置自己的代碼..

但我認爲這個問題是您Content-Type

檢查:

Content-type: text/html; charset=iso-8859-1\r\n 

text/html是必要的..

UPDATE:

的路徑是不正確的。

images/logo.jpg 

將圖像上傳到服務器(或imagehoster)並插入整個鏈接。

UPDATE 2

我想我有解決方案:

setMessageFromString()的第一個參數是純文本。第二個參數需要html內容。如果你想發送HTML - 電子郵件,檢查:

$m->setMessageFromString($plainTextBody, $HTMLBody); 
+0

查看更新的問題。 – keen

+0

向我們展示來自setMessageFromString()的代碼.. – q0re

+0

它是亞馬遜提供的SES(簡單電子郵件服務)中的一項內置功能。 – keen

0
<?php 

$to = '[email protected]'; 

$subject = 'Test email '; 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
$headers .= "From: rajeev ranjan"; 
$message='<div style="background-color:#FFFFFF;"> 

<img id="header" style="position:absolute; left:85px; top:50px; " src="images/logo.jpg" width="140" height="90" border="0" alt="" /></a> 


<img id="cloths" style="position:absolute; left:275px; top:25px;" src="images/cloths.jpg" width="350" height="300" border="0" alt="" /></a> 

<font size="7" style="font-family:Times new Roman; position:absolute; left:50px; top:120px;">Thank YOU</font> 

<font size="3" style="font-family:Times new Roman;position:absolute;left:50px; top:165px;">For registering with our team </font> 

<img id="bag" style ="position:absolute; left:290px; top:345px;"src="images/bag1.jpg" width="250" height="240" border="0" alt="" /></a> 

<img style="position:absolute; left:30px; top:440px; "id="watch" src="images/watch1.jpg" width="260" height="180" border="0" alt="" /></a> 

</div> 

'; 
//send the email 
$mail_sent = @mail($to, $subject, $message, $headers); 
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
echo $mail_sent ? "Mail sent" : "Mail failed"; 
?> 
+0

但我的主要問題是它不適用於亞馬遜服務。我沒有得到正確的輸出。正如你在我的問題中看到的那樣。任何想法爲什麼? – keen

+0

我知道這些圖像,我很快就會上傳,但即使CSS不起作用。 – keen

+0

我試圖使用你的腳本,只是改變了和。即使在這我沒有得到正確的輸出。你會請張貼你收到的電子郵件截圖嗎? – keen

相關問題