gpt4 book ai didi

PHP表单提交到多个电子邮件

转载 作者:搜寻专家 更新时间:2023-10-31 21:26:59 27 4
gpt4 key购买 nike

我有一个 php 网络表单,我想在联系我们页面上使用它。除了能够将成功的提交发送到多个电子邮件地址之外,一切都按预期工作。我试过以下方法:

$targetEmail = 'email@gmail.com', 'email2@gmail.com'; 

以及将 $targetEmail 放入一个数组中:

$targetEmail = array(
'Email1' => 'email@gmail.com',
'Email1' => 'email2@gmail.com',
);

但它永远不会提交到两个地址。任何建议将不胜感激。

完整代码如下

<?php
//****************************************
//edit here
$senderName = 'Contact Form';
$senderEmail = 'admin@gmail.com';
$targetEmail = 'email1@gmail.com';
$messageSubject = 'Contact Us Form';
$redirectToReferer = false;
$redirectURL = 'http://www.website.com/thankyou.html';
//****************************************

// mail content
$name = $_POST['name'];
$email = $_POST['email'];

// prepare message text
$messageText = 'Name: '.$name."\n".
'Email: '.$email."\n";

// send email
$senderName = "=?UTF-8?B?" . base64_encode($senderName) . "?=";
$messageSubject = "=?UTF-8?B?" . base64_encode($messageSubject) . "?=";
$messageHeaders = "From: " . $senderName . " <" . $senderEmail . ">\r\n"
. "MIME-Version: 1.0" . "\r\n"
. "Content-type: text/plain; charset=UTF-8" . "\r\n";

if (preg_match('/^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,4}$/',$targetEmail,$matches))
mail($targetEmail, $messageSubject, $messageText, $messageHeaders);

// redirect
if($redirectToReferer) {
header("Location: ".@$_SERVER['HTTP_REFERER'].'#sent');
} else {
// header("Location: ".$redirectURL);
header("Location: http://www.website.com/thankyou.html");
}
?>

最佳答案

您需要用逗号分隔字符串中的电子邮件地址:

 $targetEmail = 'email@gmail.com,email2@gmail.com'; 

使用数组,您试图用相同的键创建两个条目,因此它会覆盖它。相反,使用不同的键:

$targetEmail = array(
'Email1' => 'email@gmail.com',
'Email2' => 'email2@gmail.com',
);

关于PHP表单提交到多个电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34595048/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com