0

我是 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);
?> 
4

1 回答 1

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循环

于 2013-04-01T19:20:20.827 回答