我正在尝试向两位成员发送确认电子邮件,但我很困惑如何这样做。以下只是相关代码。 我以前在我的网站上使用过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.";
}
感谢您的帮助。
答案 0 :(得分:3)
此字符串的格式必须符合»RFC 2822。有些 例子是:
user@example.com user@example.com,alotheruser@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');
?>
答案 1 :(得分:1)
这应该有效,假设$ coinsAvail ['Email']和$ valueResultAdd ['Email']都是电子邮件地址。我会使用echo($ to);在函数中确保$ to string看起来像你想要的那样。