以下に、Ajax フォームの送信からテーブルを備えた適切な HTML メールを作成する PHP コードをいくつかまとめました。ただし、関連する情報のみが電子メールに表示/送信されるように、空白の必須ではない変数が送信されないようにしたいと考えています。何を追加する必要がありますか?
<?php
$destination = "handle@domain.com";
$email_from = $_POST['Email'];
$message = "<html>
<body style=\"font-family:Arial; font-size:10pt;\">
Hello,<br>
You have recieved an online form submission:<br><br>
<table width='600' border='1' cellspacing='3'>";
//Gather posted variables:
foreach($_POST as $keys => $vars){
$message .= "<tr>
<td bgcolor='#CCCCCC'><b>$keys:</b></td> <td><b><font color='red'>$vars</font></b></td>
</tr>";
}
$message = str_replace("_"," ", $message);
$message .= "
</table>
</body>
</html>
";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
mail($destination,"Online Form Submission",$message,"From: $email_from\n".
"Content-Type: text/html; charset=\"utf-8\"\n".
"Content-Transfer-Encoding: 7bit\n".
"MIME-Version: 1.0\n");
echo "Thank you for your submission!";
?>