2

I have the following mail function:

<?php
{
$to = "alee@####.com";
$subject = "General Contact.";
$headers  = "From: ####<noreply@####.com>\r\n";
$headers .= "Reply-To: info@####.com\r\n";
$headers .= "Return-Path: info@####.com\r\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$name = filter_input(INPUT_POST, 'name');
$telephone = filter_input(INPUT_POST, 'phone');
$nature = filter_input(INPUT_POST, 'nature');   
$comments = filter_input(INPUT_POST, 'comments');
$message = 
"<span style='font-weight: bold;'>Name: </span>"."<br />".$name."<br />"."<br />".
"<span style='font-weight: bold;'>Telephone: </span>"."<br />".$telephone."<br />"."<br   />".
"<span style='font-weight: bold;'>Nature of enquiry: </span>"."<br />".$nature."<br />"."<br />".
"<span style='font-weight: bold;'>Comments: </span>"."<br />".$comments."<br />"."<br />";

mail($to, $subject,"We have received a message via the online form at www.####.com<br />  <br />" . $message, $headers);
echo "Your message was successfully sent. Please <a href='contact.php'>click here</a> to return to the site.";
?>
<?php  }
?>

The problem I have is that when the form is used and the message hits my inbox, the HTML is being displayed as plain text, and not being displayed properly. So I can see all the inline HTML element, i.e. the
will be shown as part of the paragraph and not display a new line. Any help would be awesome!

EDIT:

Reply-To: info@###.com
Return-Path: info@###.com
MIME-Version: 1.0
Content-type: text/html; charset: utf8

We have received a message via the online form at www.###.com<br /><br /><span    style='font-weight: bold;'>Name: </span><br />Aaron Lee<br /><br /><span style='font-weight:   bold;'>Telephone: </span><br />#####<br /><br /><span style='font-weight:   bold;'>Nature of enquiry: </span><br />###<br /><br /><span style='font-weight:   bold;'>Comments: </span><br />Testttttttttttt<br /><br />
4

9 に答える 9

0

HTML 形式のメールを送信するとき、私は常に混合メールを使用しています。メール、マルチパート/混合を構築し、パーツを分割するためにいくつかの行を追加します($trenner)

私の実用的なソリューションとあなたのソリューションとの主な違いは、プロパティ Content-Transfer-Encoding です。これは、テキスト部分の場合は 7 ビット、html の場合は引用印刷可能です。

$crlf = "\r\n";
$trenner = '---wbs'.md5(uniqid(time()));

if(!$this->from)throw new exception('wbs_mail:Kein Absender angegeben');
if(!$this->to)throw new exception('wbs_mail:Kein Empfänger angegeben');
if(!$this->subject)throw new exception('wbs_mail:Kein Betreff angegeben');
if(!$this->content['html'])throw new exception('wbs_mail:Kein HTML-Inhalt angegeben');
if(!$this->content['text'])throw new exception('wbs_mail:Kein Text-Inhalt angegeben');

$this->header = "From: ".$this->from.$crlf;
$this->header  .= "X-Mailer: wbs_mail php_ver". phpversion().$crlf;
$this->header  .= "MIME-Version: 1.0".$crlf;
$this->header .= 'Content-Type: multipart/mixed; boundary="'.$trenner.'"'.$crlf;

// Der Textblock
$content = $trenner.$crlf;
$content .= 'Content-Type: text/plain; charset="iso-8859-1"'.$crlf;
$content .= 'Content-Transfer-Encoding: 7bit'.$crlf;
$content .= $this->getContent('text').$crlf.$crlf;

// Der HTML Block
$content .= $trenner.$crlf.$crlf;
$content_html = 'Content-Type: text/html; charset="iso-8859-1"'.$crlf;
$content_html .= 'Content-Transfer-Encoding: quoted-printable'.$crlf;
$content_html .= $this->getContent('html').$crlf;
$content .= $content_html.$crlf;
$content .= $trenner.$crlf;
于 2014-03-29T19:16:32.047 に答える
0

以下の行を変更してみてください。

$headers .= 'MIME-Version: 1.0' . "\n";

$headers .= 'MIME-Version: 1.0' . "\r\n";

すべての行は \r\n で終わる必要があり、それ以外のものではありません。

于 2014-03-26T13:40:26.700 に答える
0

この方法でメールを送信しています。多分あなたはそれが助けることができる何かを見ることができます:

public static function mailSend($mail_to,$fname,$mail_sub,$mail_msg,$from){

    $To=$mail_to;

    $Body =$mail_msg."<BR>";

    $Subject=$mail_sub;

    $headers  = "MIME-Version: 1.0\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\n";
    $headers .= "From: Robot <info@#####.com>  \n";
    $headers .= "X-Mailer: www.#####.com\n"; //mailer
    $headers .= "Return-Path: <info@#####.com>\n";
    $headers .= "X-Priority: 3\n"; //1 UrgentMessage, 3 Normal

    $mail = new PHPMailer();

    $mail->IsSMTP();            // set mailer to use SMTP
    $mail->IsHTML(true);

    $mail->From = $from;
    $mail->FromName = $fname;
    $mail->AddAddress($To);

    $mail->WordWrap = 100;      // set word wrap to 100 characters

    $mail->Subject = $Subject;
    $mail->Body    = $Body;
    $mail->AltBody    = $Body;

    $mail->Send();

}
于 2014-03-26T16:41:56.653 に答える
0

余分な改行を含むヘッダーを送信しているようです。

あなたの例から、ヘッダーの後に 2 つの改行があるようです。を削除してみます\rので、ヘッダーの最後の行には\n

ラインを変えてみる

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";

適切ではないことはわかっていますが、この同じ問題がこの方法で解決されるのを見てきました。

于 2014-03-25T19:22:34.207 に答える
0

メッセージ

関数に渡すメッセージmail()は有効な HTML ではありません。これが、クライアントが正しく表示されない理由である可能性があります。

これを試して:

$message =
    "<!DOCTYPE html>\r\n"
    . "<html lang="en">\r\n"
    . "<body>\r\n"
    . "We have received a message via the online form at my.domain.com<br><br>\r\n"
    . "<strong>Name:</strong><br>{$name}<br><br>\r\n"
    . "<strong>Telephone:</strong><br>{$telephone}<br><br>\r\n"
    . "<strong>Nature of enquiry:</strong><br>{$nature}<br><br>\r\n"
    . "<strong>Comments:</strong><br>{$comments}<br><br>\r\n"
    . "</body>\r\n"
    . "</html>\r\n";

また、タグ内の属性値が単一引用符ではなく二重引用符で囲まれていることを確認してください。<a href="#">link</a>あり、ではありません <a href='#'>link</a>

ヘッダー

使用しているヘッダーに関するいくつかのメモ (ただし、これが問題の原因ではないと思います):

  • \r\nヘッダーは(あなたの とは\n異なります)で区切る必要がありますMIME-Version
  • Fromの構文はFrom: <email>orである必要がありますFrom: "name" <email>
  • Reply-Toの構文はReply-To: <email>orである必要がありますReply-To: "name" <email>
  • Return-Path構文が必要Return-Path: <email>です。
  • Content-Lengthヘッダーを追加する必要があります。

これを試して:

$headers = implode(
    "\r\n",
    array(
        'From: "My Name" <noreply@my.domain.com>',
        'Reply-To: <info@my.domain.com>',
        'Return-Path: <info@my.domain.com>',
        'MIME-Version: 1.0',
        'Content-type: text/html; charset=iso-8859-1',
        'Content-Length: ' . strlen($message)
    )
);

mail() を使用しないでください

mail()PHP関数には多くの問題があります。メールの送信にサードパーティのライブラリを使用することを検討する必要があります。

Swift Mailerを見て、「メール転送」を使用しないことをお勧めします( Swift_MailTransport) ;)

于 2014-03-26T22:03:05.423 に答える