订阅表不工作(PHP) [英] Subscription form not working (PHP)

查看:115
本文介绍了订阅表不工作(PHP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想允许访问我的网站的人订阅,填写一个简短的表格,并让网站向我发送一封电子邮件的信息,但目前该表格甚至不会提交信息。一些帮助将不胜感激。

I'm trying to allow people who visit my website to subscribe by filling out a short form and having the website send me an email with the information, but at the moment the form won't even submit the information. Some help would be greatly appreciated.

<form id="ContactForm" action="mail/MailHandler.php">
  <div class="success">Form submitted!<br><strong>Look forward to our next Monthly Mailer.</strong></div>
  <fieldset>
    <div class="wrapper">
      <label class="name">
        <span class="bg"><input type="text" value="Name:" class="input"></span>
        <span class="error">*This is not a valid name.</span> 
        <span class="empty">*This field is required.</span> 
      </label>
    </div>
    <div class="wrapper">
      <label class="email">
        <span class="bg"><input type="text" value="E-mail:" class="input"></span>
        <span class="error">*This is not a valid email address.</span> 
        <span class="empty">*This field is required.</span>
      </label>
    </div>
    <div class="btns">
      <a href="mail/MailHandler.php" class="button1" data-type="submit">
        <span><strong>submit</strong></span>
        <span class="active"><strong>submit</strong></span>
      </a>
    </div>
  </fieldset>
</form>

与PHP如下

<?php
$owner_email = $_POST["myemail@address.com"];
$headers = 'From:' . $_POST["email"];
$subject = 'Monthly Mailer Subscriber ' . $_POST["name"];
$messageBody = "";

$messageBody .= '<p>' . $_POST["name"] . ' would like to be subscribed to your Monthly Mailer!</p>' . "\n";
$messageBody .= '<br>' . "\n";
$messageBody .= '<p>Email Address: ' . $_POST['email'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";

try{
    if(!mail($owner_email, $subject, $messageBody, $headers)){
        throw new Exception('mail failed');
    }else{
        echo 'mail sent';
    }
}catch(Exception $e){
    echo $e->getMessage() ."\n";
}
?>

问题解决!问题在于我的输入没有名称,并且
$ owner_email = $ _POST [myemail@address.com]的语法;
应该是
$ owner_email ='myemail@address.com';

PROBLEM SOLVED! The problem lied in that my inputs did not have names, and the syntax of $owner_email = $_POST["myemail@address.com"]; should have been $owner_email = 'myemail@address.com';

推荐答案

问题#1

您正在寻找 POST 变量,但是通过 GET ,因为您从未明确将其设置为 POST 。要解决这个变化:

You're looking for POST variables but are sending them via GET since you never explicitly set it to POST. To solve this change:

<form id="ContactForm" action="mail/MailHandler.php">

to:

<form id="ContactForm" action="mail/MailHandler.php" method="POST">

问题#2

您忘了输入姓名:

<input type="text" value="Name:" class="input">

应该是:

<input type="text" value="Name:" name="name" class="input">

问题#3

您缺少提交按钮:

<input type="submit" value="submit">

应该替换:

<a href="mail/MailHandler.php" class="button1" data-type="submit">
    <span><strong>submit</strong></span>
    <span class="active"><strong>submit</strong></span>
  </a>

这篇关于订阅表不工作(PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆