【问题标题】:Send email form with php not working [closed]使用php发送电子邮件表单不起作用[关闭]
【发布时间】:2014-07-05 14:04:17
【问题描述】:

我试图通过一个表单(来自 PageLanes 的 Minimal Form)发送一些信息,其中有一些问题,我希望用户回答这些问题。

回答部分已完成 (www.wemadeyou.pt/formulario),但我无法将用户回答的问题发送到我的电子邮件。

代码如下:

HTML

<form method="post" id="theForm" class="simform animated fadeIn" autocomplete="off" action="send.php" name="form">
    <div class="simform-inner">
        <ol class="questions">
            <li>    <span><label for="q1">Digita o teu nome, idade e localização: (Ex.: Wilson Fonseca, 23, Barreiro/Lisboa)</label></span>

                <input id="q1" name="q1" type="text" tabindex="3" />
            </li>
            <li>    <span><label for="q2">Qual é a tua área? (Front-End Development, Back-End, Webdesigner, Marketing, UI/UX Design ou Graphic Design)</label></span>

                <input id="q2" name="q2" type="text" />
            </li>
            <li>    <span><label for="q3">Porque concorres a uma posição neste projecto?</label></span>

                <input id="q3" name="q3" type="text" />
            </li>
            <li>    <span><label for="q4">Tens algum tipo de formação na área? (Escola, curso ou tutorials/autodidata)</label></span>

                <input id="q4" name="q4" type="text" />
            </li>
            <li>    <span><label for="q5">Tens alguma experiência anterior? Se sim, descreve.</label></span>

                <input id="q5" name="q5" type="text" />
            </li>
            <li>    <span><label for="q6">Sabes programar em que línguas? (Se não sabes, escreve “-”)</label></span>

                <input id="q6" name="q6" type="text" />
            </li>
            <li>    <span><label for="q7">Qual é a tua capacidade com Photoshop (Básica, Mediana, Boa, Im the King of the World!)</label></span>

                <input id="q7" name="q7" type="text" />
            </li>
            <li>    <span><label for="q8">Consideraste uma pessoa criativa? Achas que tens o perfil indicado para um projecto de longo termo? Porquê?</label></span>

                <input id="q8" name="q8" type="text" />
            </li>
            <li>    <span><label for="q9">Porque devo acreditar, que és a pessoa indicada para ser parceiro/sócio de uma Startup?</label></span>

                <input id="q9" name="q9" type="text" />
            </li>
            <li>    <span><label for="q10">Tens algum trabalho realizado? (Mesmo privado ou escolar) Se sim, coloca os links ou envia os projectos para o dropbox (em baixo!).</label></span>

                <input id="q10" name="q10" type="text" />
            </li>
            <li>    <span><label for="q11">Tens algum projecto em desenvolvimento ou que desejarias criar? Dá uma breve descrição, da tua ideia</label></span>

                <input id="q11" name="q11" type="text" />
            </li>
            <li>    <span><label for="q12">Quais são os teus objectivos, em relação ao projecto? (Pessoais e profissionais)</label></span>

                <input id="q12" name="q12" type="text" />
            </li>
            <li>    <span><label for="q13">Digita o teu email (Ex.: fake.email@gmail.com)</label></span>

                <input id="q13" name="email" type="text" />
            </li>
        </ol>
        <!-- /questions -->
        <button class="submit" type="submit" name="submit">Submeter</button>
        <div class="controls">
            <button class="next"></button>
            <div class="progress"></div>    <span class="number">
                                    <span class="number-current"></span>
    <span class="number-total"></span>
</span> <span class="error-message"></span>

        </div>
        <!-- / controls -->
    </div>

PHP

   ini_set('display_errors', 1);
    error_reporting(~0);

    $one = $_POST['q1']; // Requesting user's first name
    $two = $_POST['q2']; // first question
    $three = $_POST['q3']; // required
    $four = $_POST['q4']; // required
    $five = $_POST['q5']; // required
    $six = $_POST['q6']; // required
    $seven = $_POST['q7']; // required
    $eight = $_POST['q8']; // required
    $nine = $_POST['q9']; // required
    $ten = $_POST['q10']; // required
    $eleven = $_POST['q11']; // required
    $twelve = $_POST['q12']; // last question

    var_dump($_POST);

if(isset($_POST['submit'])){
    $to = "uniqezor@gmail.com"; // this is your Email address
    $mail_from = $_POST['email']; // this is the sender's Email address

    if(trim($_POST['email']) == '')  {
        $hasError = true;
    } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
        $hasError = true;
    } else {
        $email = trim($_POST['email']);
    }

    $subject = "Submissão de formulário de interessado!";
    $message = "Eu sou " . $one . " e respondi ao formulário o seguinte:" . "\n\n" . 
    "<strong>Pergunta 1: Qual é a tua área? </strong>" . $two . "<br/>
    <strong>Pergunta 2: Qual é a tua área? </strong>" . $three . "<br/>
    <strong>Pergunta 3: Qual é a tua área? </strong>" . $four . "<br/>
    <strong>Pergunta 4: Qual é a tua área? </strong>" . $five . "<br/>
    <strong>Pergunta 5: Qual é a tua área? </strong>" . $six . "<br/>
    <strong>Pergunta 6: Qual é a tua área? </strong>" . $seven . "<br/>
    <strong>Pergunta 7: Qual é a tua área? </strong>" . $eight . "<br/>
    <strong>Pergunta 8: Qual é a tua área? </strong>" . $nine . "<br/>
    <strong>Pergunta 9: Qual é a tua área? </strong>" . $ten . "<br/>
    <strong>Pergunta 10: Qual é a tua área? </strong>" . $eleven . "<br/>
    <strong>Pergunta 11: Qual é a tua área? </strong>" . $twelve . "<br/>";

    $headers = "Enviado por: $q1 <$mail_from>";

    mail($to,$subject,$message,$headers);
    }

【问题讨论】:

  • 邮件服务器是否在您的服务器中工作?只检查没有任何编码的邮件方法。

标签: php html forms email send


【解决方案1】:

您没有发布表单,默认方法是GET

变化:

<form id="theForm" class="simform animated fadeIn" autocomplete="off" action="send.php" name="form">

到:

<form method="post" id="theForm" class="simform animated fadeIn" autocomplete="off" action="send.php" name="form">

【讨论】:

  • 是的,OP 忘记了method="POST",此外,提交按钮没有名称(例如name="submit"
  • 我做了更改,仍然没有发送任何电子邮件
  • @uniqezor 您是否还命名了提交按钮(参见 kevinabelita 的评论)?首先要做的是在脚本顶部添加var_dump($_POST);
  • 我已经添加了kevinabelita所说的:
  • @uniqezor 你做到了吗var_dump()?顺便说一句,您的表单对电子邮件注入开放:securephpwiki.com/index.php/Email_Injection
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-08-13
  • 2011-06-06
  • 1970-01-01
  • 2021-05-20
  • 1970-01-01
  • 2012-06-14
  • 2020-08-30
相关资源
最近更新 更多