Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.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/8/mysql/61.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 从mysql检索数据并通过电子邮件发送_Php_Mysql_Email_Select - Fatal编程技术网

Php 从mysql检索数据并通过电子邮件发送

Php 从mysql检索数据并通过电子邮件发送,php,mysql,email,select,Php,Mysql,Email,Select,我有一个php页面,它显示mysql数据库中每个用户的课程计划数据,如下所示: $result = mysql_query($sql); echo "<table border='0'> <thead> <tr> <th>Class Link</th> <th>Student Skype ID</th> <th>Student Name<

我有一个php页面,它显示mysql数据库中每个用户的课程计划数据,如下所示:

$result = mysql_query($sql);

echo "<table border='0'>
<thead>
    <tr>
        <th>Class Link</th>
        <th>Student Skype ID</th>
        <th>Student Name</th>
        <th>Faculty Name</th>
        <th>Class Name</th>
        <th>USA Date (DD/MM/YY)</th>
        <th>USA Start Time</th>
        <th>USA End Time</th>
        <th>India Date (DD/MM/YY)</th>
        <th>India Start Time</th>
        <th>India End Time</th>
        <th>Status</th>
    </tr>
</thead>";

while($row = mysql_fetch_array($result))
{
    echo "<tbody>";
        echo "<tr>";
            echo "<td><a href=\"".$row['class_link']."\" target='blank'>Start Class</a></td>";
            echo "<td>" . $row['skype_id'] . "</td>";
            echo "<td>" . $row['student_name'] . "</td>";
            echo "<td>" . $row['faculty_name'] . "</td>";
            echo "<td>" . $row['subject_name'] . "</td>";
            echo "<td>" . $row['date'] . "</td>";
            echo "<td>" . $row['starttime'] . "</td>";
            echo "<td>" . $row['endtime'] . "</td>";
            echo "<td>" . $row['facdate'] . "</td>";
            echo "<td>" . $row['facstarttime'] . "</td>";
            echo "<td>" . $row['facendtime'] . "</td>";
            echo "<td>" . $row['status'] . "</td>";
    echo "</tr>";
    echo "</tbody>";
}
echo "</table>";
正如上面代码的$message中所提到的,我想将检索到的数据放入$message部分,以便将其放入邮件中


有人能帮忙吗?

根据mysql数据的来源和存储方式,您不能检索数据并将其添加到$message变量中吗

<?PHP
    $query = "SELECT * FROM yourtable WHERE youridentifier = 'unique'"
    $result = mysql_query($query) or die(mysql_error());
    while ($row = mysql_fetch_array($result)) {
        $content = $row['field with email content']
        // or if there is more than one field
        $content2 = $row['field with more email content']
    }
    // then you can create the "message" as you wish
    $message = "Greetings ".$content.",

        you are receiving this email because of blah. ".$content2."

        Thank you,
        code guy"
    // Then you can still use $message as your variable
}
?>

使用(HTML或非HTML等)将其格式化。。然后寄出去

对于多行,将while向上更改一点

<?PHP
    // give your message the starting string
    $message = 'Greetings,

        you are receiving this email as an invoice as follows:
        <table style="width: 80%;">
            <tr>
                <td>Description</td>
                <td>Cost</td>
                <td>Weight</td>
                <td>Color</td>
            </tr>
    '
    $query = "SELECT * FROM yourtable WHERE youridentifier = 'unique'"
    $result = mysql_query($query) or die(mysql_error());
    while ($row = mysql_fetch_array($result)) {
        $message .= "        <tr>";
        $message .= "            <td>".$row['itemdescription']."</td>";
        $message .= "            <td>".$row['cost']."</td>";
        $message .= "            <td>".$row['shippingweight']."</td>";
        $message .= "            <td>".$row['color']."</td>";
        $message .= "        </tr>";
    }
    // then update the message with the ending
    $message .= "
        </table>

        Thank you,
        code guy"
    // Then you can still use $message as your variable
}
?>


如果您使用的是HTML格式的电子邮件,则按此按钮,否则它将只是格式化文本。

您已经使用
mysql\u fetch\u array()
获取了行。只需在变量中串联或插入:
$message=“Some text{$row['col\u from_db']}”Michael,我在运行搜索时弹出多行,如何将它们全部输入到消息部分?+我还想保持表格格式完整,当它进入电子邮件。。
<?PHP
    // give your message the starting string
    $message = 'Greetings,

        you are receiving this email as an invoice as follows:
        <table style="width: 80%;">
            <tr>
                <td>Description</td>
                <td>Cost</td>
                <td>Weight</td>
                <td>Color</td>
            </tr>
    '
    $query = "SELECT * FROM yourtable WHERE youridentifier = 'unique'"
    $result = mysql_query($query) or die(mysql_error());
    while ($row = mysql_fetch_array($result)) {
        $message .= "        <tr>";
        $message .= "            <td>".$row['itemdescription']."</td>";
        $message .= "            <td>".$row['cost']."</td>";
        $message .= "            <td>".$row['shippingweight']."</td>";
        $message .= "            <td>".$row['color']."</td>";
        $message .= "        </tr>";
    }
    // then update the message with the ending
    $message .= "
        </table>

        Thank you,
        code guy"
    // Then you can still use $message as your variable
}
?>