PHP 表单发送空电子邮件或找不到 formmail.pl


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

我是PHP新手,所以我的代码可能有错误。 如果服务器上的另一个测试 PHP 文件工作正常,则不应缺少 formmail.pl。我正在使用Untitled4.php和send_contact2.php

这是我的《无题4》代码.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>

这是我的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";
}
?>

更改 方法="发布''">自

 method="POST" >

删除''

下面的行不起作用。

$header=$_POST['from: $name <$mail_from>'];

将其更改为此

 $header= "from: $name <$mail_from>";

如果要在字符串中使用$var变量,则需要使用双引号" 。使用单引号'时,您需要终止并concat'string bla bla'.$var.'string continues' 。用点连接.

我认为最好使用PHPMailer或其他框架来做到这一点,因为使用mail()并不安全。这个问题有很多关系,所以我决定以不同的方式完成这项任务。