我正在尝试向两名成员发送确认电子邮件,但我对如何发送确认电子邮件感到困惑。下面仅给出相关代码。 我之前在我的网站中使用过 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 = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="89fae6e4ece6e7ece5faecc9ecf1e8e4f9e5eca7eae6e4" rel="noreferrer noopener nofollow">[email protected]</a>";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
}
感谢您的帮助。
最佳答案
The formatting of this string must comply with » RFC 2822. Some examples are:
[email protected] [email protected], [email protected] User User , Another User
所以在你的情况下你可以这样做:
<?php
// multiple recipients
$to = '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="22434b46434c62475a434f524e470c414d4f" rel="noreferrer noopener nofollow">[email protected]</a>' . ', '; // note the comma
$to .= '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0b7c6e714b6e736a667b676e25686466" rel="noreferrer noopener nofollow">[email protected]</a>';
mail($to, 'the subject', 'the message', null,
'<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1a377c6d7f78777b696e7f685a7f627b776a767f34797577" rel="noreferrer noopener nofollow">[email protected]</a>');
?>
关于function - 向两个用户发送确认电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16064913/