0

I am new to WordPress. I have created a custom template with a form. This form will get information like first name, last name, and message from visitors. I want to forward this visitor information to another email such as "test@mail.com". This email address will be a dynamic one. How can I do this in WordPress? Thanks in advance.

0

The easy way would install this plugin - https://da.wordpress.org/plugins/contact-form-7/ - It's super easy to work with, and it will do what you want :)

If you don't want to use a plugin, then you would just code a contact form with html and php.

PHP:

<?php
  $firstname = $_POST['firstname'];
  $lastname = $_POST['lastname'];
  $from = $_POST['email'];
  $message = $_POST['textarea'];

  $to = "somebody@example.com";
  $subject = "My subject";
  $message = "Hello world!";
  $headers = "From: " . $email . "\r\n" .
  "CC: somebodyelse@example.com";

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

HTML:

<form action="" method="post">
    First name:<br>
    <input type="text" name="firstname">
    <br>
    Last name:<br>
    <input type="text" name="lastname">
    <br>
    Email: <br>
    <input type="email" name="email">
    <br>
    Subject:<br>
    <input type="text" name="subject">
    <br>
    Message:<br>
    <textarea name="textarea" id="" cols="30" rows="10"></textarea>
    <br>
    <input type="submit" value="Submit">
</form>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.