1

每次我访问我的网站或刷新它时,我的表单都会向我发送一封空白电子邮件(字段数据为空)。

我看了几篇提到“发布/重定向/获取”的帖子,但这让我感到困惑而不是帮助,我不确定它是否与我的确切问题有关。

这是我在网上找到的一个基本的响应式表单,必须找到 PHP 才能实际发送表单数据。(改变它以满足我的需要)

我希望我只是在某个地方错过了一个错误,但我似乎找不到它。

任何帮助将不胜感激。提前致谢。

这是基本形式(减去 css):

PHP:

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n Email: $email \n Message: $message";
$recipient = "MY EMAIL HERE";
$subject = "Portfolio Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>

HTML:

<form id="contact-form" action="/" method="post">
            <h3>Say Hello!</h3>
            <h4>Fill in the form below, and I'll get back to you as soon as i can. Thanks!</h4>
            <div>
                <label>
                    <span>Name: (required)</span>
                    <input placeholder="Please enter your name" type="text" name="name" tabindex="1" required autofocus>
                </label>
            </div>
            <div>
                <label>
                    <span>Email: (required)</span>
                    <input placeholder="Please enter your email address" type="text" name="email" tabindex="2" required>
                </label>
            </div>
            <div>
                <label>
                    <span>Telephone: (required)</span>
                    <input placeholder="Please enter your number" type="text" name="phone" tabindex="3" required>
                </label>
            </div>
            <div>
                <label>
                    <span>Message: (required)</span>
                    <textarea placeholder="Include all the details you can" type="text" name="message" tabindex="5" required></textarea>
                </label>
            </div>
            <div>
                <button name="submit" type="submit" id="contact-submit">Send Email</button>
            </div>
        </form>
4

2 回答 2

1

利用isset

<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n Email: $email \n Message: $message";
$recipient = "MY EMAIL HERE";
$subject = "Portfolio Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
}
?>

只有当它post由任何..

于 2013-10-08T10:41:28.753 回答
0

我已经在stackoverflow链接代码链接中为其他人发布了这个, 这是我的代码。让尝试,我希望它会对你有所帮助

<?PHP
$email = $_POST["emailaddress"];
$to = "you@youremail.com";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";
$message = "A visitor to your site has sent the following email address to be added to your mailing list.\n

Email Address: $email";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: you@youremailaddress.com\n";
$usermessage = "Thank you for subscribing to our mailing list.";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
?>
于 2014-01-27T13:05:07.457 回答