I have a form that is supposed to send me an email and drop to a csv file. At this point it sends the email perfectly but won't drop to the csv file and doesn't kick back any of the error messages other than the initial "required fields" message. I'm at my wits end. What am I doing wrong?
<?php
if((empty($_POST['lastname']))||(empty($_POST['firstname']))||(empty($_POST['program']))||(empty($_POST['yearinschool']))||(empty($_POST['areaofinterest']))||(empty($_POST['preferredlocation']))||(empty($_POST['car']))||(empty($_POST['interestandgoals']))||(empty($_POST['introduction']))) {
echo "<p><font color='red' size='4'>All fields with an * are required. Please use your browser's back button and try again. Thank you.</font></p>";
}
else {
if (isset ($_POST['Submit'])) {
foreach ($_POST as $p)
$data .= ',"'.$p.'"';
$data = substr ($data, 1);
$data .= "\n";
if ($csv = fopen ("../mentorapps.csv", "a")) {
if (fwrite ($csv, $data)) {
print "<h1>It worked</h1>";
}
else {
print "<h1>Internal Error</h1>";
print "<p>File not written. An internal error has occurred. A record of this log has been sent to the system administrator. Please try again.</p>";
}
}
else {
print "<h1>Internal Error</h1>";
print "<p>File not opened. An internal error has occurred. A record of this log has been sent to the system administrator. Please try again.</p>";
}
fclose ($csv);
}
else
include ("mentorapp2.htm");
$emailmessage = "2010 Mentorship Program Application\n\n\nLast Name or Family Name: $_POST[lastname]\n\nFirst Name: $_POST[firstname]\n\nPlease indicate expected program of study: $_POST[program]\n\nYear in school: $_POST[yearinschool]\n\nPlease indicate your area(s) of interest: $_POST[areaofinterest]\n\nInterested in a mentor from (select all that apply): $_POST[preferredlocation]\n\nDo you have a car and/or transportation to Portland that will enable you to meet with a Portland mentor on a regular basis? $_POST[car] $_POST[carnotes]\n\nProvide a short essay indicating why you are interested in the MBA mentorship program and what your top five mentoring goals are. \n$_POST[interestandgoals]\n\nPlease write a short biography of yourself that we can use to make an introduction to your mentor: \n$_POST[introduction]";
mail("someone@domain.com", "2010 MENTORSHIP APPLICATION $_POST[lastname], $_POST[firstname]", $emailmessage,
"CC: someone@domain.com\r\n" .
"From: someone@domain.com\r\n" .
"Reply-To: someone@domain.com\r\n" .
"X-Mailer: PHP/" . phpversion());
}
?>