通过电子邮件发送数组值

时间:2013-04-01 19:15:36

标签: php arrays email

我是PHP新手,在从数据库的html表单字段发送数据时遇到问题。我在将每个数组值插入MySQL数据库时没有问题,在尝试通过电子邮件发送数组值时,我只是得到了空白。

在电子邮件$ school中,$ first_name和$ title未返回任何数组值。请帮忙,谢谢。

   <?php

for($i = 0; $i < 5; $i++)
{
$date = date("m/d/y", time());
$referee = $_POST['referee'];
$email_address = $_POST['email_address'];
$phone = $_POST['phone'];
$gamedate = $_POST['gamedate'];
$level = $_POST['level'];
$home = $_POST['home'];
$away = $_POST['away'];
$title = $_POST['title'][$i];
$person = $_POST['person'][$i];
$first_name = $_POST['first_name'][$i];
$jersey = $_POST['jersey'][$i];
$school = $_POST['school'][$i];
$reason = $_POST['reason'][$i];
$notes = $_POST['notes'][$i];
$checkbox = $_POST['checkbox'];


$result = mysql_query("
    INSERT INTO `soccercard` (date, referee, email_address, phone, gamedate, level, home, away, title, person, first_name, jersey, school, reason,  notes, checkbox)
    VALUES ('$date', '$referee', '$email_address', '$phone', '$gamedate', '$level', '$home', '$away', '$title', '$person', '$first_name', '$jersey', '$school', '$reason', '$notes', '$checkbox');
");

}

?>

<?php
if ($title = Red)
$to = "myemail@address.com";
$subject = "Soccer Card Report Form";
$message = ("A red card was submitted by '$referee' for the '$home' vs '$away' '$level'  game. $school $first_name was issued a $title card for $reason ");
$from = "myemail@address.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
?> 

1 个答案:

答案 0 :(得分:0)

将代码更改为

   <?php

for($i = 0; $i < 5; $i++)
{
$date = date("m/d/y", time());
$referee = $_POST['referee'];
$email_address = $_POST['email_address'];
$phone = $_POST['phone'];
$gamedate = $_POST['gamedate'];
$level = $_POST['level'];
$home = $_POST['home'];
$away = $_POST['away'];
$title = $_POST['title'][$i];
$person = $_POST['person'][$i];
$first_name = $_POST['first_name'][$i];
$jersey = $_POST['jersey'][$i];
$school = $_POST['school'][$i];
$reason = $_POST['reason'][$i];
$notes = $_POST['notes'][$i];
$checkbox = $_POST['checkbox'];


$result = mysql_query("
    INSERT INTO `soccercard` (date, referee, email_address, phone, gamedate, level, home, away, title, person, first_name, jersey, school, reason,  notes, checkbox)
    VALUES ('$date', '$referee', '$email_address', '$phone', '$gamedate', '$level', '$home', '$away', '$title', '$person', '$first_name', '$jersey', '$school', '$reason', '$notes', '$checkbox');
");
if ($title == 'Red'):
$to = "myemail@address.com";
$subject = "Soccer Card Report Form";
$message = ("A red card was submitted by '$referee' for the '$home' vs '$away' '$level'  game. $school $first_name was issued a $title card for $reason ");
$from = "myemail@address.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
endif;
} //end of for loop

?>

将标题条件放入for循环