-1

我正在尝试制作一个简单的 php 表单邮件。
我所追求的只是一封看起来很漂亮的电子邮件

Name: joe blogs
Email: joe@blogs.co.uk
Message: anything.
Answer 1: Red
Answer 2: green
Answer 3: Blue

在下面的示例中,我删除了我的电子邮件地址...问题是我填写了字段并点击了提交按钮,我收到消息说消息已发送,但没有收到任何电子邮件。在我添加 $questX 字段之前一切正常,然后它停止工作。但我认为提交的 $name 没有区别。所以我很困惑。

<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
 //send email
    $email = $_REQUEST['email'] ;
    $name = $_REQUEST['name'] ;
    $quest = $_REQUEST['quest'] ;
    $questb = $_REQUEST['questb'] ;
    $questc = $_REQUEST['questc'] ;
    $subject = "Competition Entry" ;
    $message = $_REQUEST['message'] ;
    mail("MYEMAIL@HOME.com", $subject, "Name:" . $name, "From:" . $email, "Answer 1:" . 
    $quest, "Answer 2:" . $questb, "Answer 3:" . $questc, $message );
    echo "Thank you for using our mail form";
}
else
//if "email" is not filled out, display the form
{
    echo "<form method='post' action='win-a-deck2.php'>
            <label for='name'>Name:</label><input name='name' type='text'  placeholder='Enter your fullname'><br>
            <label for='email'>Email:</label><input name='email' type='text'><br>
            <label for='message'>Message:</label><br>
            <input name='message' type='text'><br>
            <label for='quest'>Question 1:</label><input name='quest' type='text'  placeholder='Answer to Question 1'><br>
            <label for='questb'>Question 2:</label><input name='questb' type='text'  placeholder='Answer to Question 2'><br>
            <label for='questc'>Question 3:</label><input name='questc' type='text'  placeholder='Answer to Question 3'><br>
            <input type='submit'>
        </form>";  
}  
?>
4

3 回答 3

0

首先,您应该编辑表单以使问题名称成为一个数组。这样,您可以将 $_POST['questions'] 用作数组,并在其上使用 foreach 循环,而不是将每个问题输入到它自己的变量中。

其次,打开错误报告,看看你得到了什么错误。

第三,你有太多的参数在mail() http://us1.php.net/manual/en/function.mail.php 你有$to,$subject,然后是一堆更多的字符串,应该都在ONE $消息字符串。

于 2013-06-05T21:31:37.103 回答
0

简单的 php 电子邮件表单:

<form action="process.php" method="post">
<ul style="list-style-type: none;">
<li>Name: <input type="text" name="name" size="30" maxlength="40"></li>
<li>&nbsp;</li>
<li>Email: <input type="text" name="email" size="30" maxlength="40"></li>
<li>&nbsp;</li>
<li><input type="submit" name="submit" value="Send"></li>
</ul>
</form>

process.php 页面的代码如下:-

Thanks, <?php
@extract($_POST);
$sub="Form feedback";
$name = stripslashes($name);
$email = stripslashes($email);
mail('admin@your-domain.com',$sub,"$name $email","From: $name <admin@your-domain.com>");
echo stripslashes($name);
?> , we will drop you a line shortly.

教程:

http://wickham43.net/formemail.php

它经过自动回复和无响应。

也仅用于一般目的:

http://php.net/manual/en/function.mail.php

于 2013-06-05T21:24:46.980 回答
0

邮件功能:

bool mail ( 
1. string $to ,
2. string $subject , 
3. string $message 
4. [, string $additional_headers 
5. [, string $additional_parameters ]] )

http://www.php.net/manual/en/function.mail.php

您正在像这样使用它:

mail(
1. "MYEMAIL@HOME.com", 
2. $subject,
3. "Name:" . $name, 
4. "From:" . $email, 
5. "Answer 1:" . 
$quest, "Answer 2:" . $questb, "Answer 3:" . $questc
6. , $message );

当然,您向函数传递了不正确的参数,这就是它不起作用的原因。尝试这个:

mail(
"MYEMAIL@HOME.com", 
$subject, 
"Name:" . $name . "Answer 1:" . $quest, "Answer 2:" . $questb
. "Answer 3:" . $quest . $message, 
"From:" . $email );
于 2013-06-05T21:30:06.837 回答