我目前正在开发一个PHP / MySQL脚本,按以下顺序执行以下操作:
1)检查DB是否有需要转换的视频 2)一旦确定需要转换视频,它就会开始转换 * 3)通知视频的“创建者”它已被创建。 * 4)通知所有视频“接收者”的用户,他们有新视频。
注意,我正在寻找上面已加星号的帮助。
这是我的基本数据库/表结构(有些部分故意遗漏,因为我不想输入它们:
video_data:
id
creator_id
needs_process
video_info
id
video_id (relational to 'id' in table above).
receiver_id
tblusers
usrID
usrFirst
usrLast
usrEmail
以下是我目前在剧本中的内容:
<?php
require("connection.php");
$rs = mysql_db_query($DBname,$sql,$link);
$data = mysql_query("SELECT * FROM video_data WHERE needs_process=1 LIMIT 1") or die(mysql_error());
while($row = mysql_fetch_array( $data ))
{
$id = $row['id'];
$sender = $row['sender_id'];
//Convert The Video Here (I've already written this code).
//Maybe Create a Thumbnail Too (I've already written this code).
}
我的问题是:在上面的代码中,我如何向“创建者”(总是1个人)发送电子邮件并通过电子邮件发送给接收者(有时是多个接收者)。而且,这些可能是“单独的”或“不同的”电子邮件。例如,创建者会收到一封电子邮件,上面写着“感谢上传!”,而收件人会收到一封说“你有新视频。”
对此的任何帮助都会很棒!
答案 0 :(得分:2)
这是这样的:
<?php
require("connection.php");
$rs = mysql_db_query($DBname,$sql,$link);
$data = mysql_query("SELECT * FROM video_data WHERE needs_process=1 LIMIT 1") or die(mysql_error());
while($row = mysql_fetch_array( $data ))
{
$id = $row['id'];
$sender = $row['sender_id'];
//Convert The Video Here (I've already written this code).
//Maybe Create a Thumbnail Too (I've already written this code).
//mail the creator
$data2 = mysql_query("SELECT * FROM tblusers WHERE usrID=$row[creator_id] LIMIT 1") or die(mysql_error());
$creatordata = mysql_fetch_array( $data2 );
mailtocreator($creatordata['userEmail'], $creatordata['usrFirst'].' '.$creatordata['usrLast']);
//mail the receiver
$data3 = mysql_query("SELECT * FROM tblusers t, video_info vi WHERE vi.video_id = $row[id] AND vi.receiver_id = t.usrID") or die(mysql_error());
while($row2 = mysql_fetch_array($data3))
{
mailtocreator($row2['userEmail'], $row2['usrFirst'].' '.$row2['usrLast'], $creatordata['usrFirst'].' '.$creatordata['usrLast']);
}
}
function mailtocreator($toemail, $toname)
{
//do send mail routine
$subject = 'video processed';
$message = 'hello '.$toname.',
Thank you for uploading video.';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($toemail, $subject, $message, $headers);
}
function mailtoreceiver($toemail, $toname, $fromname)
{
//do send mail routine
$subject = 'new video received';
$message = 'hello '.$toname.',
You just got new video from '.$fromname.'.';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($toemail, $subject, $message, $headers);
}
基本上,它只是围绕这个查询:
$data2 = mysql_query("SELECT * FROM tblusers WHERE usrID=$row[creator_id] LIMIT 1") or die(mysql_error());
检索当前上传者的详细信息(取自$ row [creator_id])和
$data3 = mysql_query("SELECT * FROM tblusers t, video_info vi WHERE vi.video_id = $row[id] AND vi.receiver_id = t.usrID") or die(mysql_error());
通过查询表tblusers和video_info来检索所有接收者,然后分别将这些信息发送给mailtocreator和mailtoreceiver。