2011-09-10 3 views
0

에서 HTML 전자 메일 보내기 사용자의 전자 메일 주소를 수집하여 데이터베이스에 제출하는 과정에 있습니다. 그러나 실제로 수행하고 싶은 작업은 HTML 전자 메일을 제출하는 것입니다.PHP 문서

내가 이메일의 HTML을 만들었습니다 (인라인 CSS로, 그것은 1 페이지 문자 그대로)과는 다음과 같습니다 enter image description here

그럼이 코드를 가져다가 PHP에서 이메일 submittingness을 썼다 :

ini_set("sendmail_from", "[email protected]"); 

    $to = $email; 
    $subject = "Ben Potter Web Design - Newsletter Form Submission"; 

    $emailthing = '  
<!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>Form Submission - Newsletter Update</title> 
</head> 
<style type="text/css"> 
body { 
    background-color:#e8faff; 
} 

p { 
    font-size:15px; 
    font-family:Georgia, "Times New Roman", Times, serif; 
    color:#141414; 
    font-style:italic; 
} 

#mainbox{ 
    background-image:url(http://www.benjaminpotter.org/Images/emailtotheuser.jpg); 
    width:345px; 
    height:404px; 
    margin-left:auto; 
    margin-right:auto; 
    display:block; 
    margin-top:50px; 
} 

#mainbox #textholder{ 
    width:279px; 
    height:300px; 
    display:block; 
    position:absolute; 
    margin-top:80px; 
    margin-left:30px; 
} 

#special{ 
    color:#72C0EF; 
    text-align:center !important; 
    font-style:normal; 
} 
</style> 
<body> 
<div id="mainbox"> 
<div id="textholder"> 
<p> 
Thanks for signing up!<br /> 
I currently have you under the email:<br /> 
<span id="special">' . $email . '</span> 
<br /> 
<br /> 
You will be receiving tri-monthly/<br /> 
quarterly emails from me, updating you<br /> 
on my latest works.<br /> 
<br /> 
Thank you for your intrest in <strong>Ben Potter 
Web Design</strong>, you will receive the first newsletter soon.<br /> 
<br /> 
<br /> 
Yours Sincerely, 
<br /> 
<strong>Ben Potter</strong> 
</p> 
</div> 
</div> 
</body> 
</html>'; 

$Rconfucious = "MIME-Version: 1.0\r\n"; 
$Rconfucious .= "Content-type: text/html; charset=iso-8859-1\r\n";   
$Rconfucious .= 'From: Ben Potter Web Design 2011 <[email protected]>' . "\r\n"; 

@mail($to, $subject, $emailthing, $Rconfucious); 

그러나 문제는이 같은 통해 제공한다는 것입니다 :

enter image description here

그러면 어떻게 제대로 작동합니까? 또한 사이드 노트 - 이메일은 항상 정크 메일로 곧바로 이동하며 이것을 변경하는 방법을 모르겠습니다 ... 사용자가 이메일을 볼 수 없게됩니다.

도움 주셔서 감사합니다.

답변

4

이메일이 HTML로 올바르게 전송됩니다. 그러나 이메일 클라이언트의 CSS/HTML 지원은 1998 년의 상황과 비슷합니다.

Gmail은 <style> 태그를 지원하지 않아 이메일이 그대로 렌더링됩니다. 각 이메일 클라이언트가 지원하는 것을보고 이에 따라 HTML 템플릿을 맞춤 설정하려면 the following chart을 살펴 보시기 바랍니다.

그래서, 기본적으로, 이메일 등으로 쓸 수있다 : 이메일에

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Form Submission - Newsletter Update</title> 
</head> 
<body bgcolor="#72c0ef"> 
<div style="background-image:url(http://www.benjaminpotter.org/Images/emailtotheuser.jpg); width:345px; height:404px; margin-left:auto; margin-right:auto; display:block; margin-top:50px;"> 
<div style="width:279px; height:300px; display:block; position:absolute; margin-top:80px; margin-left:30px;"> 
<p style="font-size:15px; font-family:Georgia, \'Times New Roman\', Times, serif; color:#141414; font-style:italic;"> 
Thanks for signing up!<br /> 
I currently have you under the email:<br /> 
<span class="color:#72C0EF; text-align:center !important; font-style:normal;">' . $email . '</span> 
<br /> 
<br /> 
You will be receiving tri-monthly/<br /> 
quarterly emails from me, updating you<br /> 
on my latest works.<br /> 
<br /> 
Thank you for your intrest in <strong>Ben Potter 
Web Design</strong>, you will receive the first newsletter soon.<br /> 
<br /> 
<br /> 
Yours Sincerely, 
<br /> 
<strong>Ben Potter</strong> 
</p> 
</div> 
</div> 
</body> 
</html> 
1

전자 메일 라이브러리를 사용하는 것이 좋습니다. SwiftMailer는 잠시 동안 주변에 있었고 매우 잘 기능적이고 강력했습니다.

HTML 메시지를 작성하는 문서는 여기에 있습니다 : http://swiftmailer.org/docs/messages.html

예를 들어,이 기존 고객을위한 HTML과 일반 텍스트 모두를 지원하는 전자 메일 메시지 작성 이메일에 대해서는

//Pass it as a parameter when you create the message 
$message = Swift_Message::newInstance('Subject here', 'My amazing body'); 

//Or set it after like this 
$message->setBody('My <em>amazing</em> body', 'text/html'); 

//Add alternative parts with addPart() 
$message->addPart('My amazing body in plain text', 'text/plain'); 

스팸에 가기를, 나는 So You'd Like To Send Some Email (Through Code)을 읽을 것을 권합니다. 열쇠는 이메일을 보내기 위해 서버를 올바르게 구성하거나 postmarkapp 또는 sendgrid

과 같은 타사 공급자를 사용하는 것입니다.

UPDATE :

위는 코드에서 이메일 처리를 개선하기위한 제안으로 의미했다. 아마도 Gmail이 태그를 지원하지 않는다는 사실을 언급하지 않았지만 전자 메일 라이브러리를 사용하도록 권유했습니다.

+1

-1 :이 위의 상황과는 아무 상관이 없습니다. 전자 메일이 HTML로 올바르게 전송됩니다. 문제는 Gmail이 '