最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Programming WordPress to Send an Email on Registration Form Submit?

matteradmin6PV0评论

(Moderator's note: The original title was: "submit button in wordpress.")

I'd like to create a registration form to send an email.

I've tried Contact Form 7 but I would like to use my own HTML <form>. I can do the entire coding but I just want to know the code for the "submit" button so that the registrations goes directly to my admin email ID as I don't think the normal HTML code for the submit button will work.

Can anyone help me out in this?

(Moderator's note: The original title was: "submit button in wordpress.")

I'd like to create a registration form to send an email.

I've tried Contact Form 7 but I would like to use my own HTML <form>. I can do the entire coding but I just want to know the code for the "submit" button so that the registrations goes directly to my admin email ID as I don't think the normal HTML code for the submit button will work.

Can anyone help me out in this?

Share Improve this question edited Dec 3, 2010 at 6:53 MikeSchinkel 37.6k14 gold badges117 silver badges132 bronze badges asked Dec 3, 2010 at 4:58 Niraj ChauhanNiraj Chauhan 8503 gold badges19 silver badges43 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

While you might be able to do something on the client with jQuery I think your best bet would be to use the Post/Redirect/Get Pattern and submit your registration form via a <form method='post'> action.

The code after the screenshot below is a "Page Template" for a "Page" illustrates how to achieve what you've asked for with WordPress. Copy the code to your theme directory as page-contact-form.php (or some other name you like better) and then create a page that has template set to "Contact Form" as you see in the screenshot (note I kept the page template as simple as possible to illustrate the technique; you'll typically have a lot more code in your real live page templates):


(source: mikeschinkel)

<?php
/*
  Template Name: Contact Form
*/
define('ADMIN_USER','mikeschinkel');
if (count($_POST)) {
  $admin_user = get_userdatabylogin(ADMIN_USER);
  $registered_email = $_POST['email'];
  wp_mail($admin_user->user_email,
    'New Site Registration',
    "New Site Registration:\n\tEmail: {$registered_email}.");
}
?>
<?php get_header(); ?>
<?php if (count($_POST)): ?>
    <p>Hey <?php echo $_POST['email']; ?>, thanks for registering!</p>
<?php else: ?>
  <form method="post">
    Email: <input type="text" name="email" />
    <input type="submit" value="Register" />
  </form>
<?php endif; ?>
<?php get_footer(); ?>

After you've created your page with the above page template it might look something like this on your external site:


(source: mikeschinkel)

And this might be what it looks like after a visitor registers:


(source: mikeschinkel)

Post a comment

comment list (0)

  1. No comments so far