PHP Mail不使用MYSQL发送

时间:2015-07-23 18:10:08

标签: php mysql forms email

我在其他几种形式上使用过相同的PHP邮件脚本但是这个脚本不起作用。我认为它没有执行。

插入查询正在成功更新!

我不知道之前的执行是否会阻止它?

            $stmt = $conn->prepare('INSERT INTO attachmenttbl
                                        (attachmentid, saleid, fileurl, category, notes)
                                    VALUES
                                        (NULL, :saleid, :fileurl, :category, :notes);');


            $stmt->bindParam(':fileurl', $target_file);
            $stmt->bindParam(':saleid', $saleid);
            $stmt->bindParam(':category', $category);
            $stmt->bindParam(':notes', $notes);

            $stmt->execute(); // working up until here

            $mail_body = '';



        function getContent() {
            global $conn;
            if ($category == "Invoice" || "Stock") {
            $query = "SELECT u.Email as email, u.FName as fname
        from attachmenttbl a 
        inner join `saletbl` AS s1 ON s1.saleid = a.saleid
        inner join `buyercompanytbl` AS b ON b.companyid = s1.buyerid
        inner join `UserTbl` AS u ON u.UserID = b.userid
        WHERE a.fileurl = '$target_file'";
            }
            elseif ($category == "Order") {
            $query = "SELECT u.Email as email, u.FName as fname
        from attachmenttbl a 
        inner join `saletbl` AS s1 ON s1.saleid = a.saleid
        inner join `SellerCompanyTbl` AS s ON s.ID = s1.sellerid
        inner join `UserTbl` AS u ON u.UserID = s.UserID
        WHERE a.fileurl = '$target_file'";  
            }
            $sql = $conn->prepare($query);
            $sql->execute();

            $row = $sql->fetchAll(PDO::FETCH_ASSOC);
            return $row;
        }
            $data = getContent();

            foreach($data as $row) {
            $Fname = $row["fname"];
            $email = $row["email"];

            $mail_body = '<html>
        <body style="color:#000; font-family: Arial, Helvetica, sans-serif; line-height:1.8em;">
        Hello ' . $Fname . ',
        <p>' . $category . ' has now been uploaded to the portal ready for you to download.</p>
        <p>You can view/download the ' . $category . ' on the portal.</p>
        <p><a href="http://portal.site.com/' . $target_file . '">Here is a link direct to the file.</a></p>
        <p>Thanks,<br />Lee</p>
        </body>
        </html>';
            $subject = "$category for $seller";
            $headers  = "From:email@site.com\r\n";
            $headers .= "Content-type: text/html\r\n";
            $to = "$email";

            $mail_result = mail($to, $subject, $mail_body, $headers);
            echo "Email sent!"; 
            }

        }

0 个答案:

没有答案