Issue with email code
Posted: Tue Oct 13, 2009 1:31 pm
Hello,
I cannot figure out why my code is not working. I create a message, use a for loop to populate it with values from an array and then send it. It doesn't send the email at all. When I remove the for loop from the middle of the $message and put it at the top of the page it populates the variables just fine but then sends just he most recent value for $course and $dept. So what's the problem?
Here's the code that doesn't work:
I cannot figure out why my code is not working. I create a message, use a for loop to populate it with values from an array and then send it. It doesn't send the email at all. When I remove the for loop from the middle of the $message and put it at the top of the page it populates the variables just fine but then sends just he most recent value for $course and $dept. So what's the problem?
Here's the code that doesn't work:
Code: Select all
<?php
$message .= "
<html>
<head>
<title>Regisration Information</title>
</head>
<body>
<div>";
$numberofcourses = count($_POST['course']);
for($i=0;$i<$numberofcourses;$i++){
$course[] = $_POST['course'][$i];
$dept[] = $_POST['dept'][$i];
message .= "
Course: $course <br />
Department: $dept <br />
";
}
$message .= "
</div>
</body>
</html>";
$message = wordwrap($message, 78);
$to = "myemail@email.edu";
$subject = "student registration";
$headers = "From: myemail@email.edu\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n\r\n";
$headers .= chunk_split(base64_encode($message));
mail($to, $subject, $message, $headers);
?>