2

我正在尝试向两名成员发送确认电子邮件,但我不知道该怎么做。以下仅是相关代码。我以前在我的网站中使用 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.";  
    }

谢谢您的帮助。

4

2 回答 2

3

根据邮件 PHP 文档

此字符串的格式必须符合 » RFC 2822。一些示例如下:

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');
?>
于 2013-04-17T16:10:35.973 回答
1

这应该可行,假设 $coinsAvail['Email'] 和 $valueResultAdd['Email'] 都是电子邮件地址。我会使用 echo($to); 在函数中确保 $to 字符串看起来像你想要的那样。

于 2013-04-17T16:10:17.783 回答