所以这可能非常简单,但我似乎可以让它在我的最终工作。我目前有一个嵌入式数组,如下所示:
$array = array (
array(
$_SESSION['Contact']['Name'],
$_SESSION['Contact']['Email']
...
)
);
我的会话数组中包含大约30个字段。使用上面的示例,我必须手动列出每个会话数组项。所以,我的问题是,有没有办法迭代Sessions数组以获得相同的上述结果。
$array = array (
array(
foreach ($_SESSION as $key => $value){
$value.", ";
}
)
);
//我的电子邮件/ CSV功能
function create_csv_string($data) {
// Open temp file pointer
if (!$fp = fopen('php://temp', 'w+')) return FALSE;
// Loop data and write to file pointer
foreach ($data as $line) fputcsv($fp, $line);
// Place stream pointer at beginning
rewind($fp);
// Return the data
return stream_get_contents($fp);
}
function send_csv_mail ($csvData, $body, $to = 'xx@xxx.com', $subject = 'Test email with attachment', $from = 'zz@zzz.com') {
// This will provide plenty adequate entropy
$multipartSep = '-----'.md5(time()).'-----';
// Arrays are much more readable
$headers = array(
"From: $from",
"Reply-To: $from",
"Content-Type: multipart/mixed; boundary=\"$multipartSep\""
);
// Make the attachment
$attachment = chunk_split(base64_encode(create_csv_string($csvData)));
// Make the body of the message
$body = "--$multipartSep\r\n"
. "Content-Type: text/plain; charset=ISO-8859-1; format=flowed\r\n"
. "Content-Transfer-Encoding: 7bit\r\n"
. "\r\n"
. "$body\r\n"
. "--$multipartSep\r\n"
. "Content-Type: text/csv\r\n"
. "Content-Transfer-Encoding: base64\r\n"
. "Content-Disposition: attachment; filename=\"file.csv\"\r\n"
. "\r\n"
. "$attachment\r\n"
. "--$multipartSep--";
// Send the email, return the result
return @mail($to, $subject, $body, implode("\r\n", $headers));
}
send_csv_mail($array, "Hello World!!!\r\n This is simple text email message.");
答案 0 :(得分:0)
好吧,我想通了。简单的答案,几乎是太明显了。
$array = array (
$_SESSION['Purchase']
);