PHP为阵列中的每个电子邮件,从另一个阵列发送唯一键[关闭]
I'm more of a front-end dev and I'm not very far with PHP. I mostly use jquery and reactjs for my applications. I'm creative when it comes to design, but I got barely any inspiration while writing something functional. I need a way to send for each unique e-mail from an array, a random key from another array to that email, but so that each email get's an unique key.
我更像是一个前端开发人员,而且我对PHP不是很了解。 我主要使用jquery和reactjs来处理我的应用程序。 在设计方面我很有创意,但在写一些功能性的时候,我几乎没有任何灵感。 我需要一种方法来发送数组中的每个唯一电子邮件,从另一个数组到该电子邮件的随机密钥,但这样每封电子邮件都是唯一的密钥。 p> div>
That doesn't sound difficult. Try something like this.
$emails = ["first@example.com", "second@example.com"];
$uniqueEmails = array_unique($emails);
$uniqueKeys = ["uniq1", "uniq2"];
foreach ($uniqueEmails as $key => $email) {
//TODO: sendMail($email, $key);
}
The array_unique() function is used to remove duplicates from your array.
As far as I understand your question, you want to send the unique key to that email address. The PHP mail function can do that for you: http://php.net/manual/en/function.mail.php.
- Be sure that every array element is unique (http://php.net/manual/en/function.array-unique.php)
- Do foreach with this array && on every iterate do the following (Take random key from second array by index && unset it (to avoid duplicate)) && send email