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

时间:2014-12-27 22:52:09

标签: php html email email-integration formmail

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

这是我的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>
&#13;
&#13;
&#13;

这是我的send_contact2.php

代码

&#13;
&#13;
<?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";
}
?>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:2)

更改      方法=&#34; POST \&#34;&GT; 到

 method="POST" >

删除\

答案 1 :(得分:0)

以下这行不会起作用。

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

将其更改为此

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

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

答案 2 :(得分:0)

我认为最好使用PHPMailer或其他框架来执行此操作,因为使用mail()并不安全。很多都与这个问题有关,所以我决定以不同的方式完成这项任务。