如何在php的电子邮件正文中发送html表? [英] How to send html table in email body in php?

查看:103
本文介绍了如何在php的电子邮件正文中发送html表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在电子邮件正文中发送动态创建html表,但在电子邮件中我收到html代码,而不是显示一个表。请帮帮我。
这是我的代码。

 <?php 
$ output ='< html>< ;主体><形式>';

$ output。='< table border =1>< tr>< th>作者< / th>< th>节点标题< / th>节点摘要< / th>节点主体< th>< th>编辑该节点< / th>< th>组< / th>< / th> ;';
while($ row = mysql_fetch_array($ sql)){



$ data = explode(''',$ query ['data']);
$ output。='< tr>< td>';

if($ row ['created']> = $ strdate&& $ row ['created ']< $ enddate){

$ output。='< a href =http:// localhost / localstage / user /'。 $ row ['uid']。 ''>'$ query ['name']。'< / a>< / td>< td>';
$ output。='< a href =http: localhost / localstage / node /'。 $ row ['nid']。 ''>'。$ row ['title']。'< / a>(New)< / td>< td>';
}
else {

$ output。='< a href =http:// localhost / localstage / user /'。 $ sql_query ['uid']。 ''>'$ query ['name']。'< / a>< / td>< td>';
$ output。='< a href =http: localhost / localstage / node /'。 $ row ['nid']。 ''>'。$ row ['title']。'< / a>(更新)< / td>< td>';
}
// $ output。=' < / td>< td>';
$ output。= $ row ['teaser']。'< / td>< td>';
if($ row ['field_provcomp_level_value '] == 0 || $ row ['field_provcomp_level_value'] == 1)< br /> {
$ output。= $ row ['body']。'< / td>< td> ;';
}
else {
$ output。='< / td>< td>';
}
$ output。=' a href =http:// localhost / localstage / abuse / report / node /'。 $ row ['nid']。 '>滥用< / a>< / td>< td>';
$ output。='< a href =http:// localhost / localstage / node /'。 $ row ['nid']。 '/ edit'> Edit< / a>< / td>< td>';
$ query = mysql_fetch_array(mysql_query(SELECT title from node Where type ='groupnode'AND nid =' $ row ['nid']。'));
$ output。= $ query ['title']。'< / td>< / tr>';
}

$ output。='< / table>< / form>< / body>< / html>';
print $ output;
$ to ='hmdnawaz @ gmail.com';
$ headers =From Ahmad \r\\\
;
// $ headers。=Reply-To:。strip_tags($ _ POST ['req-email '])。\r\\\
;
// $ headers。=CC:susan@example.com\rn;
$ headers。='MIME-版本:1.0'。\r\\\
;
$ headers。='Content-Type:text / html; charset = ISO-8859-1'。\r\\\
;
$ subject ='Email report';
mail($ to,$ subject,$ output,$ headers);
if(mail){
echo'Email sent';
}
else {
echo'发送电子邮件时出错'
}
?>


解决方案

首先你错过了HTML代码中的标签,但这不应该是一个问题。 p>

其次你的标题不正确,你有:

  $ headers = 从艾哈迈德\\\\
;
// $ headers。=Reply-To:。 strip_tags($ _ POST ['req-email'])。 \r\\\
;
// $ headers。=CC:susan@example.com\r
$ headers。='MIME-Version:1.0'。 \r\\\
;
$ headers。='Content-Type:text / html; charset = ISO-8859-1'。 \r\\\
;
$ subject ='电子邮件报告';

而不是:

  // $ headers。=Reply-To:。 strip_tags($ _ POST ['req-email'])。 \r\\\
;
// $ headers。=CC:susan@example.com\r
$ headers ='MIME-Version:1.0'。 \r\\\
;
$ headers。='Content-Type:text / html; charset = ISO-8859-1'。 \r\\\
;
$ headers。=From:Ahmad< email@email.com> \r\\\
;
$ subject ='电子邮件报告';

基本上我认为你的头应该以Mime-Version开头。



检查此代码: http://us.php。 net / manual / en / function.mail.php#example-2877


I am sending dynamically creating html table in email body but in the email I receive the html code instead of displaying a table. Please help me. Here is my code.

<?php
  $output = '<html><body><form>';

  $output .=  '<table border="1"><tr><th>Author</th><th>Node Title</th><th>Node Summary</th><th>Node Body</th><th>Edit this node</th><th>Report Abuse</th><th>Group</th></tr>';
  while($row = mysql_fetch_array($sql)) {



    $data = explode('"', $query['data']);
    $output .= '<tr><td>';

    if($row['created'] >= $strdate && $row['created'] < $enddate) {

      $output .= '<a href="http://localhost/localstage/user/' . $row['uid'] . '">' .        $query['name'] . '</a></td><td>';
      $output .= '<a href="http://localhost/localstage/node/' . $row['nid'] . '">' .        $row['title'] . '</a> (New)</td><td>';
    }
    else {

      $output .= '<a href="http://localhost/localstage/user/' . $sql_query['uid'] . '">' . $query['name'] . '</a></td><td>';
      $output .= '<a href="http://localhost/localstage/node/' . $row['nid'] . '">' . $row['title'] . '</a> (Updated)</td><td>';
    }
    //$output .= '</td><td>';
    $output .= $row['teaser'] . '</td><td>';
    if($row['field_provcomp_level_value'] == 0 || $row['field_provcomp_level_value'] == 1)<br /> {
    $output .= $row['body'] . '</td><td>';
    }
    else {
    $output .= '</td><td>';
    }
    $output .= '<a href="http://localhost/localstage/abuse/report/node/' . $row['nid'] . '">Abuse</a></td><td>';
    $output .= '<a href="http://localhost/localstage/node/' . $row['nid'] . '/edit">Edit</a></td><td>';
    $query = mysql_fetch_array(mysql_query("SELECT title from node Where type = 'groupnode' AND nid = '" . $row['nid'] . "'"));
    $output .= $query['title'] . '</td></tr>';
  }

  $output .= '</table></form></body></html>';
  print $output;
  $to = 'hmdnawaz@gmail.com';
  $headers = "From Ahmad \r\n";
  //$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
  //$headers .= "CC: susan@example.com\r\n";
  $headers .= 'MIME-Version: 1.0' . "\r\n";
  $headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
  $subject = 'Email report';
  mail($to, $subject, $output, $headers);
  if(mail) {
  echo 'Email sent';
  }
  else {
  echo 'Error sending email';
  }
?>

解决方案

First you are missing the tag in your HTML code but that should not be an issue.

Secondly your header is incorrect, you have that:

$headers = "From Ahmad \r\n";
//$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
//$headers .= "CC: susan@example.com\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
$subject = 'Email report';

instead of:

//$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
//$headers .= "CC: susan@example.com\r\n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
$headers .= "From: Ahmad <email@email.com>\r\n";
$subject = 'Email report';

Basically I think you header should start by "Mime-Version".

Check this code: http://us.php.net/manual/en/function.mail.php#example-2877

这篇关于如何在php的电子邮件正文中发送html表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆