简体   繁体   English

发送确认电子邮件给两个用户

[英]Send confirmation email to two users

I'm trying to send a confirmation email to two members but im confused as how to do so. 我正在尝试向两名成员发送确认电子邮件,但我对此感到困惑。 Below is only the relevant code. 以下只是相关代码。 Ive used PHP mail before in my website for a contact page, which is fine, but I don't know how to send it to more than one person. 我以前在我的网站上使用过PHP邮件作为联系页面,这很好,但是我不知道如何将其发送给多个人。 Can you tell me what im doing wrong please? 你能告诉我我做错了什么吗?

Function exchange: 功能交换:

 //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.";  
    }

Thank you for your help. 谢谢您的帮助。

According the the Mail PHP doc 根据邮件PHP文档

The formatting of this string must comply with » RFC 2822. Some examples are: 此字符串的格式必须符合»RFC2822。一些示例是:

user@example.com user@example.com, anotheruser@example.com User User , Another User user@example.com user@example.com,anotheruser@example.com用户用户,另一个用户

So in your case you can do like that: 因此,在您的情况下,您可以这样做:

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

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

That should work, assuming $coinsAvail['Email'] and $valueResultAdd['Email'] are both email addresses. 假设$ coinsAvail ['Email']和$ valueResultAdd ['Email']都是电子邮件地址,那应该可以。 I would use an echo($to); 我会用echo($ to); in the function to make sure the $to string looks the way you're wanting. 在函数中,以确保$ to字符串看起来像您想要的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM