sendMail
이라는 함수에서 while 루프에 정의 된 $name
변수에 액세스하려고합니다. 루프 내에서 어떻게 든 함수를 통합해야합니까? .PHP의 함수에서 while 루프의 변수에 액세스하는 방법은 무엇입니까?
<?php
while ($row = mysql_fetch_assoc($result))
{
print_r($row); echo "<br><br>";
$name = $row['Name'];
$date = $row['sDate'];
$time = $row['sTime'];
$phone = $row['Phone'];
$email = $row['Email'];
sendMail($row['Email']);
$company = $row['Company'];
$course = $row['Course'];
$ref = $row['Reference'];
$optout = $row['optout'];
echo "<tr bgcolor=#ABB5F6>
<td>$name</td>
<td>$date</td>
<td>$time</td>
<td>$phone</td>
<td>$email</td>
<td>$company</td>
<td>$course</td>
<td>$ref</td>
<td>$optout</td>
</tr>";
}
// Mail to $to and $emailarray recipients
function sendMail($to)
{
$subject = 'Test mail';
$message = 'Hello'.$name; // I want $name from the while loop
$headers = array();
$headers[] = "From:" . "[email protected]";
$headerz = implode("\r\n", $headers);
mail($to, $subject, $message, $headerz);
}
?>
sendMail ($ name)을 while 루프 (정의 이후)에 추가하면 sendMail() 안에 var에 $가 추가됩니다. 또는 모든 $ 행을 전달하여 모든 값을 가질 수 있습니다. sendMail ($ row) – somedev
변수에 액세스하고 설정할 수 있으며 함수를 호출 할 수 있지만 변수를 호출 할 수는 없습니다. mysql 확장은 구식이며 지원 중단 될 예정입니다. 새 코드는 mysqli 또는 PDO를 사용해야하며, 둘 다 준비된 문에 대한 지원과 같은 중요한 이점이 있습니다. – outis