Saya ingin menghantar dua e-mel berbeza ke dua alamat berbeza menggunakan php dalam fungsi yang sama
P粉340264283
P粉340264283 2024-04-04 22:17:09
0
1
1580

Jadi apabila produk ditempah daripada pedagang yang berdaftar di tapak web saya, saya mahu kod saya mengemas kininya sambil menghantar e-mel yang sama ke alamat e-mel syarikat kami. Apabila kod dihantar ke alamat e-mel syarikat kami, tiada e-mel dihantar kepada pedagang. Bolehkah anda memberitahu saya apa yang boleh salah? Terima kasih.

Sila ambil perhatian bahawa pembolehubah e-mel adalah milik pedagang, terutamanya akaun Gmail. Bolehkah ini menjadi had gmail atau sesuatu?

function mail_merchants_and_shoply($cart_code){
        $conn = $this -> connection;
        $merchant_sent = false;
        $shoply_sent = false;
        $query = mysqli_query($conn, "SELECT * FROM business_account ORDER BY business_id DESC")or die(mysqli_error($conn));
        while($row = mysqli_fetch_array($query)){
            $id = $row['business_id'];
            $stat = "NEW";
            $email = $row['email_add'];
            $name = $row['business_name'];
            $c_query = mysqli_query($conn, "SELECT * FROM cart_db WHERE business_id = '$id' AND cart_code = '".mysqli_real_escape_string($conn, $cart_code)."'")or die(mysqli_error($conn));
            $merchant_mail_body = "<h2>NEW ORDER</h2><ul>";
            while($arr = mysqli_fetch_array($c_query)){
                $p_id = $arr['product_id'];
                $p_query = mysqli_query($conn, "SELECT * FROM products WHERE product_id = '$p_id'")or die(mysqli_error($conn));
                $p_arr = mysqli_fetch_array($p_query);
                $image = $p_arr['product_image1_url'];
                $price = $p_arr['product_price'];
                $name = $p_arr['product_name'];

                $image = "<img src = 'https://www.shoply.ng/backend/$image' style = 'max-width: 200px; max-height: 200px'/>";

                $merchant_mail_body.="<li>$name</li> <li>$image</li> <li> $price</li>";
            }
            $merchant_mail_body .="</ul>";

            $mail_subject = "NEW SHOPLY ORDER";
            // $mailHead = implode("\r\n", ["MIME-Version:1.0","Content-type:text/html; charset =utf-8"]);

            $mailHead = "MIME-Version: 1.0" . "\r\n";
            $mailHead .= "Content-type:text/html;charset=UTF-8" . "\r\n";
            
            // Additional headers
            $mailHead .= 'From: Shoply<orders@shoply.ng>' . "\r\n";
            if(mail($email, $mail_subject, $merchant_mail_body, $mailHead)){
                $merchant_sent = true;
            }

            $s_query = mysqli_query($conn, "SELECT * FROM cart_db WHERE cart_code = '".mysqli_real_escape_string($conn, $cart_code)."'")or die(mysqli_error($conn));
            $o_query = mysqli_query($conn, "SELECT * FROM orders WHERE order_code = '".mysqli_real_escape_string($conn, $cart_code)."'")or die(mysqli_error($conn));
            $o_arr = mysqli_fetch_array($o_query);
            $location = $o_arr['delivery_location'];
            $phone = $o_arr['delivery_phone'];
            $user_fname = $_SESSION['user_fname'];
            $shoply_mail_body = "<h2>NEW ORDER</h2> FROM: $user_fname <ul>
            <li><b>Address:</b> $location</li>
            <li><b>Phone Number: </b>$phone</li>";
            // $f_arr = mysqli_fetch_array($s_query);
            // $customer_id = $f_arr['customer_id'];
            // $c_query = mysqli_query($conn, "SELECT * FROM customers WHERE customer_id= '$customer_id'")or die(mysqli_error($conn));
            // $c_arr[]
            

            
            while($row = mysqli_fetch_array($s_query)){
                $p_id = $row['product_id'];
                $p_query = mysqli_query($conn, "SELECT * FROM products WHERE product_id = '$p_id'")or die(mysqli_error($conn));
                $p_arr = mysqli_fetch_array($p_query);
                $image = $p_arr['product_image1_url'];
                $price = $p_arr['product_price'];
                $name = $p_arr['product_name'];
                $image = "<img src = 'https://www.shoply.ng/backend/$image' style = 'max-width: 200px; max-height: 200px'/>";

                $shoply_mail_body.="<li>$name</li> <li>$image</li> <li> $price</li>";
            }  
            $shoply_mail_body .="</ul>";
            $email = "sales@shoply.ng";
            $mail_subject = "NEW SHOPLY ORDER";
            // $mail_head = implode("\r\n", ["MIME-Version:1.0","Content-type:text/html; charset =utf-8"]);

            $headers = "MIME-Version: 1.0" . "\r\n";
            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
            
            // Additional headers
            $headers .= 'From: Shoply<orders@shoply.ng>' . "\r\n";


            if(mail($email, $mail_subject, $shoply_mail_body, $headers)){
                $shoply_sent = true;
            }

            if($merchant_sent && $shoply_sent){
                return true;
            }else{
                return false;
            }
        }
    }

P粉340264283
P粉340264283

membalas semua(1)
P粉642919823

Saya mengesyorkan menggunakan mel php dan bukannya fungsi mel terbina dalam.

Fungsi mail() PHP menggunakan pelayan mel asas pelayan, yang pada pengehosan dikongsi selalunya mempunyai reputasi e-mel yang buruk dan oleh itu disekat oleh banyak pelayan penerima. PHP Mailer membolehkan anda berkomunikasi secara langsung dengan mana-mana pelayan web luaran, atau bahkan melalui Gmail jika anda ingin menghantar e-mel.

https://github.com/PHPMailer/PHPMailer

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!