データベースに含まれ、レコードセットに並べ替えられた複数の電子メール アドレスに電子メールを送信しようとしています... レコードセットには複数の列がありますが、「電子メール」の 1 つだけが必要です。配列にそれらがある場合、それらを内破してコンマで区切ることができることはわかっていますが、レコードセット列でそれを行う方法がわかりません。誰でも方法を知っていますか?
レコードセット コードは次のとおりです。
$colname_rsAllLeads = "-1";
if (isset($_SESSION['MM_Username'])) {
$colname_rsAllLeads = $_SESSION['MM_Username'];
}
mysql_select_db($database_myBackOfficeConn, $myBackOfficeConn);
$query_rsAllLeads = sprintf("SELECT Email FROM Leads WHERE `User` = %s ORDER BY FullName ASC", GetSQLValueString($colname_rsAllLeads, "text"));
$rsAllLeads = mysql_query($query_rsAllLeads, $myBackOfficeConn) or die(mysql_error());
$row_rsAllLeads = mysql_fetch_assoc($rsAllLeads);
$totalRows_rsAllLeads = mysql_num_rows($rsAllLeads);
新しいコード:
$colname_rsAllLeads = "-1";
if (isset($_SESSION['MM_Username'])) {
$colname_rsAllLeads = $_SESSION['MM_Username'];
}
mysql_select_db($database_myBackOfficeConn, $myBackOfficeConn);
$query_rsAllLeads = sprintf("SELECT Email FROM Leads WHERE `User` = %s ORDER BY FullName ASC", GetSQLValueString($colname_rsAllLeads, "text"));
$rsAllLeads = mysql_query($query_rsAllLeads, $myBackOfficeConn) or die(mysql_error());
$row_rsAllLeads = mysql_fetch_assoc($rsAllLeads);
$totalRows_rsAllLeads = mysql_num_rows($rsAllLeads);
$row_rsAllLeads = array();
while( $row = mysql_fetch_assoc($rsAllLeads) ) {
$row_rsAllLeads[] = $row;
}
$glued = "";
$separator = "";
foreach( $row_rsAllLeads as $row ) {
$glued .= $separator . $row['Email'];
$separator = ", ";
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) {
$startcode = $_POST['messagefield'];
$replaced = preg_replace( '/\\\\(?="|\')/', '', $startcode );
echo $replaced;
$collectedleads = $row_rsAllLeads['Email'];
echo $collectedleads;
/*
$to = $collectedleads;
$subject = $_POST['subjectfield'];
$body = $replaced;
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: " . $row_rs_CurrentUser['FirstName'] . " " . $row_rs_CurrentUser['LastName'] . " <" . $row_rs_CurrentUser['Email'] . ">";
if (mail($to, $subject, $body, $headers)) {
} else {
echo("<p>Message delivery failed...</p>");
}
*/
$insertSQL = sprintf("INSERT INTO PendingEmails (`to`, subject, message) VALUES (%s, %s, %s)",
GetSQLValueString($row_rsAllLeads['Email'], "text"),
GetSQLValueString($_POST['subjectfield'], "text"),
GetSQLValueString($_POST['messagefield'], "text"));
mysql_select_db($database_myBackOfficeConn, $myBackOfficeConn);
$Result1 = mysql_query($insertSQL, $myBackOfficeConn) or die(mysql_error());
$insertGoTo = "Email Sent.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}