2013-09-23 3 views
1

PHP로 웹 사이트를 개발 중이며 사용자가 가입 할 때 전자 메일을 보내려고합니다.AWS를 사용하여 전자 메일을 보낼 때 CSS가 작동하지 않습니다.

성공적으로 할 수 있습니다. 심지어 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; 

OLDER 은 간단합니다. 귀하의 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/j를 처리하지 않습니다. 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)에 업로드하고 전체 링크를 삽입하십시오.

setMessageFromString()에서 첫 번째 매개 변수는 일반 텍스트 :

UPDATE 2

나는 내가 해결책을 가지고 생각합니다. 두 번째 매개 변수에는 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

하지만 내 주요 문제는 Amazon 서비스에서 작동하지 않는다는 것입니다. 나는 적절한 출력을 얻지 못하고있다. 당신이 내 질문에서 볼 수 있듯이. 왜 그런가? – keen

+0

이미지에 대해 알고 있고 곧 업로드 하겠지만 CSS도 작동하지 않습니다. – keen

+0

나는 당신의 스크립트를 사용하려고 시도했다. 그리고 심지어 이것에서 나는 적절한 결과를 얻지 못합니다. 받은 이메일 스크린 샷을 게시 하시겠습니까? – keen

관련 문제