-2

我对联系表格和php知之甚少。

我正在从模板构建一个网站,它具有这种形式。

你能告诉我在contact.php中输入什么代码来发送输入的信息。

还有它会从什么电子邮件发送?

我在哪里确定它发送到哪个电子邮件地址?

谢谢你!

<form method="post" action="contact.php" id="contactform">

                <div>
                <p>Send us a message</p>
                </div>

                <div>
                <label>Name <span class="required">*</span></label>
                <input name="name" type="text" id="name" value="" />
                </div>

                <div>
                <label>Email <span class="required">*</span></label>
                <input name="email" type="text" id="email" value="" />
                </div>

                <div>
                <label>Phone Number <span class="required">*</span></label>
                <input name="Phone Number" type="text" id="Phone Number" value="" />
                </div>

                <div>
                <label>Subject</label>
                <input name="subject" type="text" id="subject"  value="" />
                </div>

                <div>
                <label>Message <span class="required">*</span></label>
                <textarea name="message" rows="20" cols="50"  id="message" ></textarea><br /><br />
                </div>

                <div>
                <input type="submit"  value="Submit" class="button">
                <input type="reset" value="Reset" class="button">
                </div>


            </form>
4

2 回答 2

1

干得好..

<form method="get" action="contact.php" id="contactform" name="contactform">

                <div>
                <p>Send us a message</p>
                </div>

                <div>
                <label>Name <span class="required">*</span></label>
                <input name="name" type="text" id="name" value="" />
                </div>

                <div>
                <label>Email <span class="required">*</span></label>
                <input name="email" type="text" id="email" value="" />
                </div>

                <div>
                <label>Phone Number <span class="required">*</span></label>
                <input name="PhoneNumber" type="text" id="Phone Number" value="" />
                </div>

                <div>
                <label>Subject</label>
                <input name="subject" type="text" id="subject"  value="" />
                </div>

                <div>
                <label>Message <span class="required">*</span></label>
                <textarea name="message" rows="20" cols="50"  id="message" ></textarea><br /><br />
                </div>

                <div>
                <input type="submit"  value="Submit" class="button">
                <input type="reset" value="Reset" class="button">
                </div>


            </form>

你的 php 文件

<?php
                if (isset($_REQUEST['contactform']))
                {
                    echo $name = $_REQUEST['name'];
                    echo $email = $_REQUEST['email'];
                    echo $PhoneNumber = $_REQUEST['PhoneNumber'];
                    echo $subject = $_REQUEST['subject'];
                    echo $message = $_REQUEST['message'];

                }
                ?>

使用此代码发送电子邮件

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>
于 2013-07-06T15:03:27.167 回答
0

Once you have validated the form input (if necessary), you should generate a string and then use the mail function to send an email.

// contact.php
if (isset($_REQUEST['contactform'])) {
     # validate the form's input if necessary

     $message = "Name: " . $_POST['name'] . "\nPhone No.:" . $_POST['Phone Number'] . "\nMessage:" . $_POST['message'];

     mail ('you@example.com', 'Contact form:' . $_POST['subject'], $message, "From: {$_POST['email']}");
}
于 2013-07-06T15:07:24.513 回答