duanboshe0001 2013-07-02 13:29
浏览 54
已采纳

我的表格,关于电子邮件位

I've searched stack but couldn't find something similar. I found a nice php script with a robot attached to the form. It works when I send a message and I do receive it. BUT, the email bit doesn't show up in the mail. Maybe you can find something more that is wrong. It's all in Swedish so nevermind the text :P

<?php
            if($_POST){
                $to = 'my@mail.com';
                $subject = 'Portfolio-mail';
                $from_name = $_POST['name'];
                $from_email = $_POST['email'];
                $message = $_POST['message'];
                $robotest = $_POST['robotest'];
                if($robotest)
                    $error = "* Misstänkt f&ouml;r att vara en robot, vad god försök igen!";
                else{
                    if($from_name && $from_email && $message){
                        $header = "Fr&aring;n: $from_name, $from_email";
                        if(mail($to, $from_email, $from_name, $message))
                            $success = "Ditt meddelande har skickats!";
                        else
                            $error = "* Du är m&auml;nsklig, men det var ett fel med din f&ouml;rfr&aring;gan!";
                    }else
                        $error = "* Alla f&auml;lt m&aring;ste vara ifyllda!";
                }
            }
        ?>

And for the input bit:

<form action="" method="POST" autocomplete="off">
                <div class="formLeft">
                    <label>För- & Efternamn:</label>
                    <input type="text" id="name" name="name" placeholder="John Doe" required="required">

                    <label>Email-adress:</label>
                    <input type="text" id="email" name="email" placeholder="Fyll i din email-adress!" required="required">
                </div>
                <div class="formRight">
                    <label>Skriv gärna in några ord angående projektet.</label>
                    <textarea id="textarea" name="message" placeholder="Klicka i denna ruta för att börja skriva..." required="required"></textarea>
                    <p class="robotic" id="pot">
                        <label>If you're human leave this blank:</label>
                        <input name="robotest" type="text" id="robotest" class="robotest" />
                    </p>
                    <input type="submit" value="Skicka!" />
                </div>
            </form>

That's it! If you need more information, don't hesitate to ask!

  • 写回答

1条回答 默认 最新

  • dsh8009271 2013-07-02 13:35
    关注

    You are using the php mail function incorrectly:

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

    You have

    if(mail($to, $from_email, $from_name, $message))
    

    With your code you have many of these variables you just aren't using them, it should be

    if(mail($to, $subject, $message, $header))
    

    In the future please at least look at the php documentation before posting a question. http://php.net/manual/en/function.mail.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效