简体   繁体   中英

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. 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

The formatting of this string must comply with » RFC 2822. Some examples are:

user@example.com user@example.com, anotheruser@example.com User User , Another User

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. I would use an echo($to); in the function to make sure the $to string looks the way you're wanting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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