phphtmlemailformmail

PHP Form sends empty emails or formmail.pl can't be found


I am new to PHP so I might have a mistake in my code. formmail.pl shouldn't be missing if another test php file on the server works fine. I am working with Untitled4.php and send_contact2.php

Here is my code for Untitled4.php

<html>

   
              <form action="/cgi-bin/formmail/formmail.pl" method="POST">
                <div align="left">
                  <hr>


                  <body>
                    <table width="450" border="0" align="right" cellpadding="3" cellspacing="1">
                      <tr>

                        <td><strong><Contact Form</strong>
                        </td>
                      </tr>
                    </table>

                    <table width="450" border="0" align="center" cellpadding="0" cellspacing="1">
                      <tr>
                        <td>
                          <form name="form1" method="post" action="send_contact2.php">

                            <img src="service.png" style="height: 42px; width: 533px" />
                            <p style="color: #FF0000">

                              <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
                                <tr>
                                  <td width="10%">Name</td>
                                  <td width="2%">:</td>
                                  <td width="82%">
                                    <input name="name" type="text" id="name" size="50">
                                  </td>

                                </tr>



                                <tr>
                                  <td>Address</td>
                                  <td>:</td>
                                  <td>
                                    <input name="address" type="text" id="address" size="50">
                                  </td>
                                </tr>

                                <tr>
                                  <td>City</td>
                                  <td>:</td>
                                  <td>
                                    <input name="city" type="text" id="city" size="50">
                                  </td>
                                </tr>

                                <tr>
                                  <td>Phone Number</td>
                                  <td>:</td>
                                  <td>
                                    <input name="phone" type="text" id="phone" size="50">
                                  </td>
                                </tr>

                                <tr>
                                  <td>Email</td>
                                  <td>:</td>
                                  <td>
                                    <input name="customer_mail" type="text" id="customer_mail" size="50">
                                  </td>
                                </tr>

                                <tr>
                                  <td>Number of Dogs</td>
                                  <td>:</td>
                                  <td>
                                    <select name="dogs" id="dogs">
                                      <option value="1">1</option>
                                      </option>
                                      <option value="2">2</option>
                                      </option>
                                      <option value="3">3</option>
                                      </option>
                                      <option value="4+">4+</option>
                                      </option>
                                    </select>
                                  </td>
                                </tr>

                                <tr>
                                  <td>Type of Service</td>
                                  <td>:</td>
                                  <td>
                                    <select name="service_type" id="service_type">
                                      <option value="Weekly">Weekly</option>
                                      </option>
                                      <option value="BiWeekly">Bi-Weekly</option>
                                      </option>
                                      <option value="Twice a Week">Twice a Week</option>
                                      </option>
                                      <option value="One Time Cleanup">One Time Cleanup</option>
                                      </option>
                                    </select>
                                  </td>
                                </tr>

                                <tr>
                                  <td>Comments Questions</td>
                                  <td>:</td>
                                  <td>
                                    <textarea name="address" cols="50" rows="4" id="address"></textarea>
                                  </td>
                                </tr>


                                <tr>
                                  <td>&nbsp;</td>
                                  <td>&nbsp;</td>

                                  <td>
                                    <input type="submit" name="Submit" value="Submit">
                                    <input type="reset" name="Submit2" value="Reset">
                                  </td>
                                </tr>
                              </table>


                  </body>

</html>

Here is my code for send_contact2.php

<?php
// Contact subject
$subject=$_POST['name'];
// Details
$address=$_POST['address'];
$city=$_POST['city'];
$phone=$_POST['phone'];
$customer_mail=$_POST['customer_mail'];
$dogs=$_POST['dogs'];
$service_type=$_POST['service_type'];
$completemessage="Address:$address  City:$city  Phone:$phone  Email:$customer_mail  Number of Dogs:$dogs  Service Type:$service_type";

$message=$_POST['address', 'city', 'phone', 'customer_mail', 'dogs', 'service_type'];

// Mail of Sender
$mail_from=$_POST['customer_mail'];
// From
$header=$_POST['from: $name <$mail_from>'];

// Enter your email address
$to="someone@test.com";

$send_contact=mail($to,$subject,$completemessage,$header);

// Check if message sent to your email
// display message "we've received your info"
if($send_contact){
echo "We've recieved your information.";
}
else
{
echo "Error";
}
?>


Solution

  • I think it would be better to use PHPMailer or some other framework to do this because using mail() is not as secure. A lot ties into this problem, so I have decided to do this task a different way.