After doing this to your code:
if ($listing != '') {
if ($action == 'mail'){
$subject = $sender . ' sent you email about one of ' .
'your cars listed on organization.com';
$fromName = $yourname;
$fromAddres = $youremail;
$message = $sender . ' would like more information. ' .
'You can click the link below.<br>' .
"\r\n" . $baseurl . '/view.php?view=' .
$listing . "\r\n\r\n" . $comment;
$message = stripslashes($message);
$temp = mail($agentemail, $subject, $message, 'From: ' .
$fromName . ' <' . $fromAddress . '>')
or print 'Could not send mail.<br /><hr /r><br /><p>';
if ($temp = true) {
print '<center><table width="760"><tr>';
print '<td height="300" valign="top" class="main">';
print 'The email has been sent.<br />';
print '<img src="images/sent_mail.jpg"><br />';
print '<a href="' . $baseurl . '/view.php?view=' .
$listing . '">Return to listing' . $listing;
print '</a></td></tr></table></center>';
}
} else {
print '<form name="mailman" action="./dealermail.php' .
'?listing=' . $listing . '&' . $agentemail .
'&action=mail" method="post"><center>';
print '<table border="0" cellpadding="0" cellspacing="0" width="760">';
print '<tr><td></td><td class="main"><b>Email about this.</b></td></tr>';
print '<tr><td width="120" align="right" class="main">Dealer\\'s Email:';
print '</td><td align="left" class="main">';
print '<input type="hidden" name="' . $agentemail . '">' . $agentemail;
print '</td></tr>';
print '<tr><td width="120" align="right" class="main">Your name:</td>';
print '<td align="left"><input type="text" name="sender" /></td></tr>';
print '<tr><td width="120" align="right" class="main">Your message:</td>';
print '<td align="left"><textarea name="comment" cols="60" rows="4">';
print '</textarea></td></tr><tr><td></td>';
print '<td align="middle" class="main">';
print '<input type="submit" value="Send" />';
print '</td></tr></table></center></form>';
}
}
...I was able to read it well enough to see that in your "action" value ("./dealermail.php?listing=' . $listing . '&' . $agentemail . '&action=mail") you insert "$agentemail" but give it no name (e.g. "name="), which, if it existed, is what you'd want to use in your "mail()" function instead of "$agentemail".
And you'd be better off in the long run if you used the modern-day convention of turning "register_globals" to "off", or at least coding as if it were.