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

编程入门 行业动态 更新时间:2024-10-09 20:23:29
本文介绍了从mysql检索数据并发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个php页面,显示mysql数据库中每个用户的类调度数据,如下所示:

$ result = mysql_query ($的SQL); echo< table border ='0'> < thead> < tr> < Class Link< / th& < th>学生Skype ID< / th> < th>学生名称< / th> < th>教师名称< / th> & ;类名称< / th> < th>美国日期(DD / MM / YY)< / th> <美国开始时间< / th> &美国结束时间< / th> >印度日期(DD / MM / YY)< / th> < th>印度开始时间< / th> < th>印度结束时间< / th> < th>状态< / th> < / tr> < / thead> while($ row = mysql_fetch_array($ result)) { echo< tbody>; echo< tr>; echo< td>< a href = \$ row ['class_link']。\target ='blank'>开始类< / 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>;

现在我有以下php电子邮件脚本

$ to ='support@xyz'; $ subject =你的班级表; $ message = **'如何从MYSQL中输入数据?'**; $ headers ='From:REPLY@XYZ.COM'。 \\\\。 $ headers =MIME-Version:1.0。 \\\\。 $ headers =Content-type:text / html; charset = iso-8859-1。 \\\\。 '回复:REPLY@XYZ.COM'。 \\\\。 'X-Mailer:PHP /'。 phpversion(); mail($ to,$ subject,$ message,$ headers);

如上面代码的$ message所提到的,我想将这个检索到的数据放入$消息部分,以便它进入邮件..

任何人都可以帮助?

解决方案

根据您的mysql数据的来源,如何存储它不能检索它,只需将其添加到$ message变量中。

<$ p $ $ result = mysql_query($ query)or die(mysql_error())$ p $ $ $ $ $ $ $ $ $ $ $ $ $ ; while($ row = mysql_fetch_array($ result)){ $ content = $ row ['mail with email content'] //或者如果有多个字段 $ content2 = $ row ['有更多电子邮件内容的字段'] } //那么你可以根据需要创建message $ message =Greetings$ content 你收到这封电子邮件是因为blah。$ content2。 谢谢你,代码人 //那么你仍然可以使用$ message作为变量} ?>

按照你的格式(HTML或不等等)..和邮件。 >

多行更改一段时间..

<? PHP //给您的消息开始字符串 $ message ='问候, 您收到这封电子邮件作为发票如下:<表风格=width:80%;> < tr> < td>说明< / td> < td>成本< / td> < td>重量< / td> < td>颜色< / 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>; } //然后更新消息结束 $ message。=< / table> 谢谢 code guy //那么你仍然可以使用$ message作为你的变量} ?>

如果您使用的是HTML格式的电子邮件,那么这是一个倒数,否则只是格式化的文本。 / p>

I have a php page which displays class schedule data for each user from mysql database like this:

$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>";

now i have the following php email script

$to = 'support@xyz'; $subject = "Your Class Schedule"; $message = **'HOW CAN I PUT THE DATA FROM MYSQL HERE?'**; $headers = 'From: REPLY@XYZ.COM' . "\r\n" . $headers = "MIME-Version: 1.0" . "\r\n" . $headers = "Content-type:text/html;charset=iso-8859-1" . "\r\n" . 'Reply-To: REPLY@XYZ.COM' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers);

As mentioned in the $message of the above code i would like to put this retrieved data into the $ message section so that it goes in the mail..

can anyone help?

解决方案

depending on the source of your mysql data and how it is stored can't you retrieve it and just add it to the $message variable?

<?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 } ?>

format it as you with (HTML or not, etc) .. and mail away.

for multiple rows change the while up a little..

<?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 } ?>

That pressumption is if you are using HTML formatted emails, otherwise it'll just be formatted text.

更多推荐

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

本文发布于:2023-10-12 16:15:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485243.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送电子邮件   数据   mysql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!