There is a form with optional fields. It is necessary, if you do not fill in these fields, then output the letter without the "empty" of these fields.

I tried to do it like this, but apparently some kind of mistake. The letter just stopped coming.

<?php $to = ''; $firstname = $_POST["name"]; $email= $_POST["email"]; $text= $_POST["message"]; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= "From: " . $email . "\r\n"; // Sender's E-mail $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; if (!empty($text)) { $message ='<table style="width:100%"> <tr> <td>'.$firstname.'</td> </tr> <tr><td>Email:<b> '.$email.'</b></td></tr> </table>'; } else { $message ='<table style="width:100%"> <tr> <td>'.$firstname.'</td> </tr> <tr><td>Email:<b> '.$email.'</b></td></tr> <tr><td>Text: '.$text.'</td></tr> </table>'; } @mail($to, $email, $message, $headers) ?> 
  • More precisely, it always comes after what else. - Gregory
  • Check for the existence of such fields in general by the function isset () - doox911
  • Here you do not check that the mail() function returned, do not look at the error log. And the script is generally worked? And after that ask what is wrong ?! - ArchDemon 3:31 pm

0