0

我是 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>

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

4

3 回答 3

2

将方法=“POST\”更改为

 method="POST" >

消除 \

于 2015-01-09T09:45:06.183 回答
0

下面的行是行不通的。

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

改成这个

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

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

于 2014-12-27T22:55:40.687 回答
0

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

于 2015-01-08T19:38:29.080 回答