问候我一直试图将通知脚本组合在一起,以便在客户需要的商品已上载到数据库时通知客户。到目前为止,我已经设法将客户的需求与数据库中的需求进行匹配,现在问题是通知客户该商品可以通过电子邮件获得。这是我设法整理的代码
<?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>";
}*/
}
}
}}