dongren1353 2019-01-28 13:13
浏览 26

通知php脚本

Greetings I have been stuck trying to put together a notification script that informs a customer when an item they want has been uploaded to the database. so far i have managed to fetch and match what the customer wants with what's on the database the problem now is notifying the customer that the item is available via email. This is the code i've managed to put together

<?php
require 'dbh.php';
require 'dbu.php';
require 'phpmailer/PHPMailer/PHPMailerAutoload.php';


        $sql="SELECT product_name,product_price,userID,location,category,first_name FROM notification";
        $result= mysqli_query($con, $sql);
        $queryResult=mysqli_num_rows($result);
        echo "".$queryResult."<hr>";
        if ($queryResult>0) {
            while ($row=mysqli_fetch_assoc($result)) {
                $name=$row['product_name'];
                $price=$row['product_price'];
                $location=$row['location'];
                $category=$row['category'];
                $email=$row['userID'];
                $first_name=$row['first_name'];
                $product_details=array($name,$price);
                $final=implode("",$product_details);
                echo "<br>".$final."<hr>";                                              
            $sql2="SELECT id,product_name,product_price,location,category FROM products";
            $result2= mysqli_query($con,$sql2);
            $queryResult2=mysqli_num_rows($result);
             if ($queryResult2>0) {
                while ($res=mysqli_fetch_assoc($result2)) {
                $product_details2= array($res['product_name'],$res['product_price']);
                        $final2=implode('', $product_details2);
                        $results=similar_text($final, $final2,$perc);

                        if ($perc>=60) {

                            //echo "<br>Product ID:".$res['id']." Similar by ".$perc."%<br>";
                            echo "".ceil($perc)."%
                                 ".$res['id']."
                                 ".$res['product_name']."
                                 ".$res['product_price']."
                                 ".$res['location']." ".$email."<br>";

                            $mail = new PHPMailer;
                            $mail->isSMTP();                                   // Set mailer to use SMTP
                            $mail->Host = '';                    // Specify main and backup SMTP servers
                            $mail->SMTPAuth = true;                            // Enable SMTP authentication
                            $mail->Username = '';          // SMTP username
                            $mail->Password = ''; // SMTP password
                            $mail->SMTPSecure = 'ssl';                         // Enable TLS encryption, `ssl` also accepted
                            $mail->Port = 465;                                 // TCP port to connect to

                            $mail->setFrom('notify@example.COM', 'Notification Email');
                            $mail->addReplyTo('notify@example.com', 'Notification Email');
                            $mail->addAddress($email);   // Add a recipient
                            //$mail->addCC('cc@example.com');
                            //$mail->addBCC('bcc@example.com');

                            $mail->isHTML(true);  // Set email format to HTML

                            $bodyContent = 'Hello '.$first_name.',

                                    An Item that matches what you requested is available click the link below to 
                                    check it out
                                    http://localhost/notify.php?email='.$email.'&hash=';

                            $mail->Subject = 'Item Notification (example.com)';
                            $mail->Body    = $bodyContent;




                }/*else{
                    echo "<br>not a close match<br>";
                }*/
             }
            }
        }}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100