2013-08-23 17 views
6

このPHPの電子メール機能の結果として、ランダムな場所に感嘆符が表示されています。私はそれが私の行が長すぎるか、Base64で電子メールをエンコードしなければならないことを読みましたが、私はそれを行う方法を知らないです。感嘆符がランダムにPHPのHTML-Eメールの結果

これは私が持っているものです。

$to = "[email protected]"; 
$subject = "Pulling Hair Out"; 
$from = "[email protected]"; 
$headers = "From:" . $from; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
$headers .= "Content-Transfer-Encoding: 64bit\r\n"; 

mail($to,$subject,$message,$headers); 

全くランダムはありませんので、私はこれをどのように修正すればよいです!結果には?ありがとう!

+0

空のメール本文でもこの問題が発生しますか? –

+0

質問に例を追加できますか? – andrewsi

+0

この質問は尋ねられ、ここで答えられました:http://stackoverflow.com/questions/7921111/exclamation-point-in-html-email?rq=1 – Lumberjack

答えて

8

ここに述べたように:Exclamation Point in HTML Email

問題は、あなたの文字列が長すぎるということです。メール機能に78文字より長いHTML文字列を入力すると、!あなたの弦の中で(強打)。あなたの電子メールが長すぎるため、

これはRFC2822 http://tools.ietf.org/html/rfc2822#section-2.1.1

+0

私はこの他の質問 "HTMLメールの感嘆符"を読んだ。私はこれを行う方法を正確にはわかりません: "解決策は、データをエンコードするか、\ r \ nを私の長い行のhtmlコードに追加することです。" – Tom

+3

てみ@tomuky '$ base64_email_text = RTRIM(chunk_split(BASE64_ENCODE($のemail_text)));' 出典: http://www.brightlemon.com/blog/unexpected-exclamation-marks-while-using- phps-mail-function-0 – sampoh

1

あなたが正しいの行の長さの制限に起因して、それがあります。メールヘッダーのこの行に置き換えてください。

Content-Transfer-Encoding: quoted-printable 
+0

これはうまくいかなかった。 – Tom

+0

あなたがまだそれを理解したのかどうかはわかりませんが、私はこのコードを削除しました。だからこのヘッダーはあなたの問題を解決するはずです。 '$ message = quoted_printable_encode($ message)' http://php.net/manual/en/function.quoted-printable-encode.php – FatBat

+0

私は、上記の数多くの回答と私自身のいくつかの回避策で腹を立てましたが、これは間違いなく最も簡単で最も速い修正で、出力にはキックバックはありませんでした。 $ headers。= "Content-Transfer-Encoding:quoted-printable"。 "\ r \ n"; 私のHTML文字列を調整しました: $ body = quoted_printable_encode($ msgtosend); –

3

は、コードのこの部分を使用してみてください:

$to = "[email protected]"; 
$subject = "Pulling Hair Out"; 
$from = "[email protected]"; 
$headers = "From:" . $from; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
$headers .= "Content-Transfer-Encoding: 64bit\r\n"; 

$finalMessage = wordwrap($message, 75, "\n"); 

mail($to,$subject,$finalMessage,$headers); 

問題は、1行が長い998文字を超えてはならないということです。 (https://stackoverflow.com/a/12840338/2136148も参照してください)

2

ここでの回答には、行の長さに関する正しい情報がありますが、問題を解決するのに十分なコードスニペットが提供されていません。私は周りを見回し、これを行うための最善の方法を見つけました、ここにあります。

<?php 
// send base64 encoded email to allow large strings that will not get broken up 
// ============================================== 
$eol = "\r\n"; 
// a random hash will be necessary to send mixed content 
$separator = md5(time()); 

$headers = "MIME-Version: 1.0".$eol; 
$headers .= "From: Me <[email protected]>".$eol; 
$headers .= "Content-Type: multipart/alternative; boundary=\"$separator\"".$eol; 
$headers .= "--$separator".$eol; 
$headers .= "Content-Type: text/html; charset=utf-8".$eol; 
$headers .= "Content-Transfer-Encoding: base64".$eol.$eol; 

// message body 
$body = rtrim(chunk_split(base64_encode($html))); 

mail($email, $subject, $body, $headers); 
// ============================================== 
+0

コードはほぼ完成です。エラーがあります。 '$ headers。=" Content-Transfer-Encoding:base64 "$ eol。$ eol;'という行は間違っているので、$ headers。= "Content-Transfer-Encoding:base64"でなければなりません。$ eol'してうまくいくでしょう – OfficeYA

+0

あなたの例では2番目の '$ eol'を削除していますか? – Novocaine

関連する問題