Hi Requinix
Thanks for answering.
I will try to explain it more clear and descripe better.
(I am aware that mail () is not optimal and not at all with html. Is of course in the process of rewriting so it works with phpmailer.)
I have an html form where I want to send data from inputs via mail.
In order for the email not to be filled with lines stating that "0" items are being ordered, my thought is that I will test whether $item5 is empty or 0.
If it's empty or "0" the line should not be sent in mail. If, on the other hand, there is "1" or more, the line must appear in the email.
In the code below, it is only $item5 I have tested on, but the intention is that it is all lines of items to be tested on.
I have many lines. More than in the example below
<?php
if(!isset($_POST['submit']))
{
echo "Error; you need to submit the form!";
}
$address =$_POST['address'];
$tlf =$_POST['tlf'];
$date =$_POST['date'];
$ordernote =$_POST['ordernote'];
$project =$_POST['project'];
$item1 = $_POST['DW'];
$item2 = $_POST['DW1'];
$item3 = $_POST['AF1'];
$item4 = $_POST['AF2'];
$item5 = $_POST['PIGM1'];
$visitor_mail = $_POST['visitormail'];
$visitor_name = $_POST['visitorname'];
//Validate
if(empty($address)||empty($tlf))
{
echo "Address and tlf need to be filled";
exit;
}
$email_from = '
[email protected]';
$email_subject = 'My subject';
$email_body = '<html><head><style type="text/css">td { width: 450; }</style></head><body>';
$email_body .= '<h2>New form submitted</h2>';
$email_body .= '<table border="0" width="900">';
$email_body .= '<tr><td><strong>Info:</strong></td><td></td></tr>';
$email_body .= '<tr><td><strong>Address:</strong></td><td>' . $adresse . '</td></tr>';
$email_body .= '<tr><td><strong>Phone:</strong></td><td>' . $tlf . '</td></tr>';
$email_body .= '<tr><td><strong>Date:</strong></td><td>' . $date . '</td></tr>';
$email_body .= '<tr><td><strong>Project number:</strong></td><td>' . $project . '</td></tr>';
$email_body .= '<tr><td><strong>Notes:</strong></td><td>' . $ordernote . '</td></tr>';
$email_body .= '</table><br />';
$email_body .= '<table border="0" width="900">';
$email_body .= '<tr><td><strong>Items info:</strong></td><td></td></tr>';
$email_body .= '<tr><td></td><td>' . $item1 . ' pcs. of item 1 is ordered</td></tr>';
$email_body .= '<tr><td></td><td>' . $item2 . ' pcs. of item 2 is ordered</td></tr>';
$email_body .= '<tr><td></td><td>' . $item3 . ' pcs. of item 3 is ordered</td></tr>';
$email_body .= '<tr><td></td><td>' . $item4 . ' pcs. of item 4 is ordered</td></tr>';
//if (empty($vare5)) {
// echo '$email_body .= "";';
//}
if (isset($item5))
{
$email_body .= '<tr><td></td><td>' . $item5 . ' pcs. of item 5 is ordered</td></tr>';
}
$email_body .= '</table><br />';
$email_body .= '</body></html>';
$to = "
[email protected]";
$headers = "From: Project form <". $email_from .">\r\n";
//$headers .= "Cc: <". $visitor_mail .">"\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();
mail($to,$email_subject,$email_body,$headers);
header('Location: thank-you.html');
?>