簡體   English   中英

發送確認電子郵件給兩個用戶

[英]Send confirmation email to two users

我正在嘗試向兩名成員發送確認電子郵件,但我對此感到困惑。 以下只是相關代碼。 我以前在我的網站上使用過PHP郵件作為聯系頁面,這很好,但是我不知道如何將其發送給多個人。 你能告訴我我做錯了什么嗎?

功能交換:

 //full code for exchange not included

// Redirect to index page if exchange is successful  
if ($success){
        sendMail($coinsAvail['Email'],$valueResultAdd['Email'],$valueResultAdd['OddJobName']);
        header("location: index.php?success=yes&email={$valueResultAdd['Email']}");
    }
        else{
            if($success)
             header("location: index.php?success=no&email={$valueResultAdd['Email']}");
        }
        exit();

function to send email
    }
    //Send a confirmation email to both members
    function sendMail($purchaseEmail, $oddjobEmail, $oddJobName)
    {
        $to = "$purchaseEmail, $oddjobEmail";
        $subject = "$oddJobName";
        $message = "Hello! $oddJobName has been requested by $purchaseEmail.";
        $from = "someonelse@example.com";
        $headers = "From:" . $from;
        mail($to,$subject,$message,$headers);
        echo "Mail Sent.";  
    }

謝謝您的幫助。

根據郵件PHP文檔

此字符串的格式必須符合»RFC2822。一些示例是:

user@example.com user@example.com,anotheruser@example.com用戶用戶,另一個用戶

因此,在您的情況下,您可以這樣做:

<?php
// multiple recipients
$to  = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';

mail($to, 'the subject', 'the message', null,
   '-fwebmaster@example.com');
?>

假設$ coinsAvail ['Email']和$ valueResultAdd ['Email']都是電子郵件地址,那應該可以。 我會用echo($ to); 在函數中,以確保$ to字符串看起來像您想要的方式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM