douzhu3367 2013-02-03 00:32
浏览 69

我的PHP联系表格不起作用

I am creating a website and I was making a contact form with PHP. It is turning up no errors on the page itself but the email never shows up in the inbox or spam folder of my email. The code I have for it is:

        $_NAME = $_POST["name"];
        $_EMAIL = $_POST["reply"];
        $_SUBJECT = $_POST["subject"];
        $_MESSAGE = $_POST["message"];

        $_MAILTO = "myemail@gmail.com";
        $_SUBJECT = "Contact Form";
        $_FORMCONTENT = "From: ".$_NAME." Subject: ".$_SUBJECT." Message: ".$_MESSAGE;
        $_MAILHEADER = "Reply To: ".$_EMAIL;

        mail($_MAILTO, $_SUBJECT, $_FORMCONTENT, $_MAILHEADER);

Any ideas what the problem is?

EDIT --

Here's the HTML form:

<form id="contact" name="contact" action="contact2.php" method="post">
                <input type="text" class="name" name="name" id="name" placeholder="Your name (optional)" onfocus="placeholder=''" onblur="placeholder='Your name (optional)'" /><br><br>
                <input type="text" class="reply" id="reply" name="reply" placeholder="Your email (optional)" onfocus="placeholder=''" onblur="placeholder='Your email (optional)'" /><br><br>
                <input type="text" class="subject" id="subject" name="subject" placeholder="Subject" onfocus="placeholder=''" onblur="placeholder='Subject'" /><br><br>
                <textarea class="message" id="message" name="message" rows="10" cols="50" placeholder="Enter your message" onfocus="placeholder=''" onblur="placeholder='Enter your message'"></textarea><br><br>
                <input type="submit" class="send" id="send" name="send" value="Send Message" />
            </form>
  • 写回答

2条回答 默认 最新

  • dotn30471 2013-02-03 00:42
    关注

    First step would be to check the return value of the mail function to see if the email was successfully (as far as PHP/mail function can ascertain) sent.

    $mail_result = mail($_MAILTO, $_SUBJECT, $_FORMCONTENT, $_MAILHEADER);
    if ($mail_result) {
        echo <<<HTML
    <div>Mail was successfully sent!</div>
    HTML;
    } else {
        echo <<<HTML
    <div>Sending mail failed!</div>
    HTML;
    }
    

    Secondly, you should check that all appropriate settings are correctly set in your php.ini file, specifically the sendmail_path setting. You should definitely take a look at official documentation in the PHP Manual.

    As a last ditch effort, you may want to look into an alternate method of sending the mail.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看