Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.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函数,我想在电子邮件中传递。问题是我该怎么做 function pmEmailTbl($JobNumber) { include('pmconnect.php'); $sql = "SELECT tblUnitMaster.UnitID, tblUnitMaster.JobNumber, tblUnitMaster.Scope, tblJobMaster.JobNumber, tblJobMaster.UnitQty, tblJobMaster.SalesEng

我不知道该怎么办。我有一个php函数,我想在电子邮件中传递。问题是我该怎么做

function pmEmailTbl($JobNumber)
{

include('pmconnect.php');
$sql = "SELECT tblUnitMaster.UnitID, tblUnitMaster.JobNumber, tblUnitMaster.Scope, tblJobMaster.JobNumber, tblJobMaster.UnitQty, tblJobMaster.SalesEng, tblJobMaster.PriorityCode, tblJobMaster.SalesNote, tblUnitMaster.JobCode, tblUnitMaster.ModelNumber, tblUnitMaster.RTU FROM tblJobMaster\n"
. "LEFT JOIN tblUnitMaster\n"
. "ON tblJobMaster.JobNumber=tblUnitMaster.JobNumber\n"
. "WHERE tblUnitMaster.JobNumber = '" . $JobNumber . "' ";
$result=$conn->query($sql);

echo "<style>";
echo "th {";
echo "background-color: #6EB4FF;";
echo "color: white;";
echo "}";

echo "</style>";

echo "<table border=2 cellpadding=2 cellspacing=5>";

echo "<tr>";
echo "<th><b><font size=3>"."Job"."</font></b></th>";
echo "<th><b><font size=3>"."Tag"."</font></b></th>";
echo "<th><b><font size=3>"."Model Number"."</font></b></th>";
echo "<th><b><font size=3>"."Sales Eng"."</font></b></th>";
echo "<th><b><font size=3>"."Priority"."</font></b></th>";
echo "<th><b><font size=3>"."Scope"."</font></b></th>";

echo "</tr>";

while ($row=$result->fetch_array())
    {
    echo "<tr>";
    echo "<td><font color=black size=3>",substr($row[0],0,4) , $row[8] , substr($row[0],4,3),"</font></td>"; // Unit Number
    echo "<td><font color=black size=3>".$row[10]."</font></td>"; //RTU Number
    echo "<td><font color=black size=3>".$row[9]."</font></td>"; // Model Number
    echo "<td><font color=black size=3>".$row[5]."</font></td>"; // SalesEng
    echo "<td><font color=black size=3>".$row[6]."</font></td>"; // PriorityCode
    echo "<td><font color=black size=3>".$row[2]."</font></td>"; // Scope

    echo "</tr>";   
    }
echo "</table>";

echo "<br>";

}
我没有问题的电子邮件,除了事实上,我不能通过简单的表,我想。我试图避免将表作为附件发送

编辑

这是电子邮件的代码。这正是它应该发挥的作用

$JobNumber=1111;
$JobCode='F';
$SalesNote='Sales note for job handoff';
$quote='Forest Quote';
$JobNumberCode = substr($JobNumber,0,4) . $JobCode ;

$to = '';

$headers['From'] = 'forest';
$headers['Subject'] = $JobNumberCode . " Job Handoff";

// create MIME object
$mime = new Mail_mime;

// add body parts
$html = '<html><body><p>Job: '  . $JobNumber . ' has been handed off from sales.</p>
<p>Please review and assign an Engineer as soon as possible.</p>


<table border=2 cellpadding=4 cellspacing=10>

<tr>
<th><b><font color=STEELBLUE size=3>Note</font></b></th>
</tr>

<tr>
<td><font color=black size=2>' . $SalesNote . '</font></td>
</tr>  

</table>

<p>Visit master record for Job info.</p>

<p>Thank You,</p>
<p>FOREST</p>
<p>' . $quote . '</p>
</body></html>';

$mime->setHTMLBody($html);

// get MIME formatted message headers and body
$headers = $mime->headers($headers);
$body = $mime->get();

@$message =& Mail::factory('mail');
$message->send($to, $headers, $body);
$JobNumber=1111;
$JobCode='F';
$salesfote='Sales note for job handoff';
$quote='forestquote';
$JobNumberCode=substr($JobNumber,0,4)$工作代码;
$to='';
$headers['From']='forest';
$headers['Subject']=$JobNumberCode。“工作交接”;
//创建MIME对象
$mime=新邮件\u mime;
//添加身体部位
$html='作业:'$工作编号。”已从销售部移交

请尽快审查并指派一名工程师

注 ' . $销售说明。” 访问主记录以获取工作信息

谢谢,

森林

"$引用

'; $mime->setHTMLBody($html); //获取MIME格式的消息头和正文 $headers=$mime->headers($headers); $body=$mime->get(); @$message=&Mail::工厂('Mail'); $message->send($to,$headers,$body);
您的函数
pmEmailTable
正在使用
echo
语句构建表。这些需要更改为将创建的字符串存储在变量中,然后在函数结束时返回该变量

示例

function pmEmailTbl($JobNumber)
{
    // Skipped to first use of echo to start example
    $table = "<style>"; // Here you start by replacing your first echo with $table =
    $table .= "th {";  // You will notice here that we use $table .= to replace echo
    $table .= "background-color: #6EB4FF;"; // .= will concatenate your new string
    $table .= "color: white;"; //to the end of the existing variable
    $table .= "}";
    // Keep replacing echos till you get to the last one
    return $table; //This you add at the end of the function to return the  table
}
函数pmEmailTbl($JobNumber)
{
//跳到第一次使用echo开始示例
$table=“”;//在这里,您首先将第一个echo替换为$table=
$table.=“th{”//您会注意到这里我们使用$table.=替换echo
$table.=“背景色:#6EB4FF;”;//.=将连接新字符串
$table.=“color:white;”;//到现有变量的末尾
$table.=“}”;
//继续更换echos,直到找到最后一个
return$table;//您可以在函数末尾添加它来返回表
}

为了简单起见,我删掉了一些,但基本上这就是你所缺少的。目前您正在使用echo。echo所做的只是打印出一些内容。在本例中,您希望将该内容存储到一个变量中,然后可以在函数末尾使用该变量。通过这种方式,您的函数可以按照您希望的方式使用,即调用
$EmailTbl=pmEmailTbl($JobNumber)
,您将生成表格,然后将其存储在
$EmailTbl

中。实际上,您并没有使用此脚本发送电子邮件。您是否在询问如何发送包含此动态创建的表的电子邮件?请查看此lib@obsidiange,我非常清楚该脚本没有发送电子邮件。该脚本仅用于表。就像我说的,我对电子邮件没有任何问题。问题是电子邮件中没有我想要的表。创建上面的表没有明显的“错误”(除了
$sql
中的回车);它应该成功地输出一个表。您能否更新您的问题,以便它也显示您的电子邮件是如何创建的?@Obsidiage请参阅电子邮件编码的编辑您能详细解释一下吗?当然,我非常乐意!我已经更新了我的答案,为你提供了更多的细节@elliottanthank。唯一的问题,我现在有,我得到的工作编号随机在最后一列。查看图片,而不是表格是按照我的要求在电子邮件中发送的。
function pmEmailTbl($JobNumber)
{
    // Skipped to first use of echo to start example
    $table = "<style>"; // Here you start by replacing your first echo with $table =
    $table .= "th {";  // You will notice here that we use $table .= to replace echo
    $table .= "background-color: #6EB4FF;"; // .= will concatenate your new string
    $table .= "color: white;"; //to the end of the existing variable
    $table .= "}";
    // Keep replacing echos till you get to the last one
    return $table; //This you add at the end of the function to return the  table
}