繁体   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