doubi6215 2017-07-24 13:14
浏览 36
已采纳

如何通过PHP脚本从表单发送多个输入到电子邮件

So I have this little php script which upon form completion sends the information to my email. I was able to make it work with one input, however, when trying to specify 3 different inputs, it won't go through.

I suspect that maybe I'm not specifying the inputs as I should with isset at the beginning of the if statement. I'm very new to php and appreciate all the help I can get, anyway here's the code.

       <?php

    if (isset($_POST['name' && 'emailq' && 'message'])){
  $visitor_name = $_POST['name'];
  $visitor_email = $_POST['emailq'];
  $visitor_message = $_POST['message'];

  $email_from = "LightDesigns";
  $email_subject = "new quot";
  $email_body = "Name: " .$visitor_name."
Email: " .$visitor_email."

" 
 .$visitor_message;

  $to = "stefanvujic576@gmail.com";
  $headers = "From: $email_from 
";
  $headers .= "Reply-To: $visitor_email 
";
  $result = mail($to,$email_subject,$email_body,$headers);
}
?>

<?php
$link_address = 'www.light-designsonline.co.uk';
if ($result){
    echo '<link href="css/phpcss.css" rel="stylesheet">';
    echo "<header></header>";
    echo '<h1>Thank You!</h1>';
    echo "<p>I'll get in contact with you shortly.</p>";

 }else{
    echo '<link href="css/phpcss.css" rel="stylesheet">';
    echo "<header></header>";
  ?>
  }
 <?php
  }
?>

<form action="quotform.php" method="POST" class="quote" name="quot">
        <div>
        <h1>Get a quot</h1>
        <hr align="left" style="width: 82%;">
            <label>Name</label><br>
            <input type="text" placeholder="Name" class="form" autocomplete required name="name">
                </div>
                    <div>
                        <label>Email</label><br>
                        <input type="email" placeholder="Email Address" class="form" autocomplete required name="emailq"> 
                    </div>
                <div>
            <label>Message</label><br>
            <textarea placeholder="Message" name="message"></textarea>
        </div>
            <button class="button_1" type="submit" class="form"><span>Send</span></button>
    </form>
  • 写回答

3条回答 默认 最新

  • dpbvpgvrhwxen3222 2017-07-24 13:17
    关注

    it's wrong

    if (isset($_POST['name' && 'emailq' && 'message'])){
    

    it means to AND together 'name', 'emailq' and 'message' values, which will be a logical TRUE and checked if the $_POST array has a value with the key TRUE

    what you need is

    if (isset($_POST['name']) && isset($_POST['emailq']) && isset($_POST['message'])){
    

    or you could use

    if (isset($_POST['name'], $_POST['emailq'],$_POST['message'])){
    

    as mentioned by Magnus Eriksson

    each has to be a separate logical expression which are then ANDed together

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥200 csgo2的viewmatrix值是否还有别的获取方式
  • ¥15 Stable Diffusion,用Ebsynth utility在视频选帧图重绘,第一步报错,蒙版和帧图没法生成,怎么处理啊
  • ¥15 请把下列每一行代码完整地读懂并注释出来
  • ¥15 pycharm运行main文件,显示没有conda环境
  • ¥15 寻找公式识别开发,自动识别整页文档、图像公式的软件
  • ¥15 为什么eclipse不能再下载了?
  • ¥15 编辑cmake lists 明明写了project项目名,但是还是报错怎么回事
  • ¥15 关于#计算机视觉#的问题:求一份高质量桥梁多病害数据集
  • ¥15 特定网页无法访问,已排除网页问题
  • ¥50 如何将脑的图像投影到颅骨上