2013-09-23 62 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

相关问题