2011-09-10 10 views
0

私はユーザーの電子メールアドレスを収集してデータベースに送信する過程にありますが、本当にやりたいことはHTMLメールを送信することです。PHPの文書からHTMLメールを送信する

私は、電子メールの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>タグをサポートしていません。 the following chartを見て、各電子メールクライアントがサポートしていることを確認し、それに従ってHTMLテンプレートを調整することをお勧めします。

だから、基本的に、あなたの電子メールのような書かなければなりません:電子メールでの

<!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メッセージを作成するためのドキュメントはここにある:スパムに行くのメールについて

//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'); 

:たとえばhttp://swiftmailer.org/docs/messages.html

、これはレガシークライアントのためのHTMLとプレーンテキストの両方をサポートしている電子メールメッセージを作成し、私はSo You'd Like To Send Some Email (Through Code)を読むことをお勧めします。重要な点は、電子メールを送信するためにサーバーを正しく設定するか、postmarkappまたはsendgrid

のようなサードパーティプロバイダを使用することです。

UPDATE:

上記のコード内で電子メールの取り扱いを改善するための提案としてのものでした。おそらく、Gmailがタグをサポートしていないという事実には触れていないかもしれませんが、私は電子メールライブラリの使用を推奨しています。

+1

-1:これは上記のような状況とは何の関係もありません。電子メールはHTMLとして正しく送信されています。問題は、Gmailが「