Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
提交时用php生成html电子邮件_Php_Html - Fatal编程技术网

提交时用php生成html电子邮件

提交时用php生成html电子邮件,php,html,Php,Html,我正在试图弄清楚如何在php文件中编写html。php似乎无法识别所有的html标记,如font、img。它给出了一个错误。我试着回显“html内容”;但它似乎不太管用 我在下面的代码中省略了另一个$var声明。除了我尝试添加字体大小或img标记时,脚本正在工作 <?php header("Content-type: html"); $message = " <!DOCTYPE html> <htm

我正在试图弄清楚如何在php文件中编写html。php似乎无法识别所有的html标记,如font、img。它给出了一个错误。我试着回显“html内容”;但它似乎不太管用

我在下面的代码中省略了另一个$var声明。除了我尝试添加字体大小或img标记时,脚本正在工作

  <?php
        header("Content-type: html");


        $message = "
        <!DOCTYPE html>
         <html>
         <head>
             <title>New Loan Enquiry</title>
        </head>
        <body>

        <h2><strong>Time of Enquiry: $today</strong></h2>

        Name: $name<br>
        Email: $email<br>
        Contact: $contact<br>
        Buy_Stage: $buystage<br>
        Property Type: $pty_type<br>
        Property Stage: $pty_stage<br>
        Purchase Price: $purchaseprice<br>
        Loan Amount: $loanamt<br>
        Rate Type: $rate_type<br>
        Comments: $comments<br><br>



        </body>
        </html>

        ";

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

?>

我哪里出错了?它能识别h2,但不能识别h1或h3

我必须像你一样做吗

回音“html”

对于每个html代码行?

您需要添加

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";


$headers .= 'From: <from@example.com>' . "\r\n";
$headers .= 'Cc: cc@example.com' . "\r\n";
请签入文档

要发送包含html内容的电子邮件,您需要采用以下方式:

<?php

$to  = 'aidan@example.com';

// subject
$subject = 'subject of email';

// message
$message = 'some html content...';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?>

我发现在
php
中设置
Html
电子邮件样式最好是使用如下表格和内联样式。这里有一个参考链接,遗憾的是,内部和外部样式表并不总是在不同的电子邮件客户端之间工作

    <?php
            $headers  = 'MIME-Version: 1.0' . "\r\n";
            $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";




              $message = '<html>';
              $message .= '<head>';
              $message .= '<title>New Loan Enquiry</title>';
              $message .= '</head>';
              $message .= '<body>';

              $message .= '<h2><strong>Time of Enquiry: $today</strong></h2>';
              $message .= '<img src="http://YOUR_IMAGE_URL"/>;
              $message .= '<table width="auto" border="0" cellspacing="3px" cellpadding="0">';
              $message .= '<tr><td><strong>Name:</strong></td>';
              $message .= '<td style=" font-weight:300 color:#CC0000">\$name</td></tr>';
              $message .= '<tr><td><strong>Email:</strong></td>';
              $message .= '<td style=" font-weight:300 color:#CC0000">\$email</td></tr>';
              $message .= '<tr><td><strong>Contact:</strong></td>';
              $message .= '<td style=" font-weight:300 color:#CC0000">\$contact</td></tr>';
              $message .= '<tr><td><strong>Buy_Stage:</strong></td>';
              $message .= '<td style=" font-weight:300 color:#CC0000">\$buystage</td></tr>';
              $message .= '<tr><td><strong>Property Type:</strong></td>';
              $message .= '<td style=" font-weight:300 color:#CC0000">\$pty_type</td></tr>';
              $message .= '<tr><td><strong>Property Stage:</strong></td>';
              $message .= '<td style=" font-weight:300 color:#CC0000">\$pty_stage</td></tr>';
              $message .= '<tr><td><strong>Purchase Price:</strong></td>';
              $message .= '<td style=" font-weight:300 color:#CC0000">\$purchaseprice</td></tr>';
              $message .= '<tr><td><strong>Loan Amount:</strong></td>';
              $message .= '<td style=" font-weight:300 color:#CC0000">\$loanamt</td></tr>';
              $message .= '<tr><td><strong>Rate Type:</strong></td>';
              $message .= '<td>\$rate_type</td></tr>';
              $message .= '<tr><td><strong>Comments:</strong></td>';
              $message .= '<td style=" font-weight:300 color:#CC0000">\$comments</td></tr>';

            $message .= '</table>';

            $message .= '</body></html>';

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

您正在为要添加的项目转义字符吗?您需要向我们提供您想要使用的代码。mail()部分工作正常,这些$string的值也正确显示在电子邮件上。我的问题是$message的html格式。例如,我尝试将Contact:$Contact添加到其中一行,但电子邮件不会反映字体大小的更改。这可能是由于标题问题,我没有正确地指出。请告诉我你有问题的代码,就像你试图添加的图像
header("Content-type: html");
    <?php
            $headers  = 'MIME-Version: 1.0' . "\r\n";
            $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";




              $message = '<html>';
              $message .= '<head>';
              $message .= '<title>New Loan Enquiry</title>';
              $message .= '</head>';
              $message .= '<body>';

              $message .= '<h2><strong>Time of Enquiry: $today</strong></h2>';
              $message .= '<img src="http://YOUR_IMAGE_URL"/>;
              $message .= '<table width="auto" border="0" cellspacing="3px" cellpadding="0">';
              $message .= '<tr><td><strong>Name:</strong></td>';
              $message .= '<td style=" font-weight:300 color:#CC0000">\$name</td></tr>';
              $message .= '<tr><td><strong>Email:</strong></td>';
              $message .= '<td style=" font-weight:300 color:#CC0000">\$email</td></tr>';
              $message .= '<tr><td><strong>Contact:</strong></td>';
              $message .= '<td style=" font-weight:300 color:#CC0000">\$contact</td></tr>';
              $message .= '<tr><td><strong>Buy_Stage:</strong></td>';
              $message .= '<td style=" font-weight:300 color:#CC0000">\$buystage</td></tr>';
              $message .= '<tr><td><strong>Property Type:</strong></td>';
              $message .= '<td style=" font-weight:300 color:#CC0000">\$pty_type</td></tr>';
              $message .= '<tr><td><strong>Property Stage:</strong></td>';
              $message .= '<td style=" font-weight:300 color:#CC0000">\$pty_stage</td></tr>';
              $message .= '<tr><td><strong>Purchase Price:</strong></td>';
              $message .= '<td style=" font-weight:300 color:#CC0000">\$purchaseprice</td></tr>';
              $message .= '<tr><td><strong>Loan Amount:</strong></td>';
              $message .= '<td style=" font-weight:300 color:#CC0000">\$loanamt</td></tr>';
              $message .= '<tr><td><strong>Rate Type:</strong></td>';
              $message .= '<td>\$rate_type</td></tr>';
              $message .= '<tr><td><strong>Comments:</strong></td>';
              $message .= '<td style=" font-weight:300 color:#CC0000">\$comments</td></tr>';

            $message .= '</table>';

            $message .= '</body></html>';

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