Use PHP to Mail a Form

Using php to mail a form is a simple task. Grab the codes below to learn how to do it yourself. This is continuation of our last lesson “Create a Form in a PHP Function“.

Edit the Functions.php File

In order to accomplish this you will edit your functions.php form to look like it does below. This will give you more form inputs like email, subject and message.

[code]<?php

function form(){
echo ‘
<form method="post" action="">
<input type="text"name="firstName"placeholder="First Name"/>
<input type="email" name="email"placeholder="email"/>
<input type="text" name="subject" placeholder="subject" />
<textarea name="message"placeholder="your message here"></textarea>
<input type="submit" name="submit" value="submit"/>
</form>

Only cool people share!

‘;
}

?>[/code]

Edit the Index.php File

Now edit your index.php file so that you can grab the post variables in php. After grabbing the post variables you will be able to email yourself a copy.

[code]<?php if(isset($_POST[‘submit’])){ echo $_POST[‘firstName’].’ your email has been sent’; $to=$_POST[’email’]; $subject=$_POST[‘subject’]; $message=$_POST[‘message’]; $firstname=$_POST[‘firstName’]; $headers = ‘From: max@a1websitepro.com’ . "\r\n" . ‘Reply-To: noreply@yourwebsite.com’ . "\r\n" . ‘X-Mailer: PHP/’ . phpversion(); mail($to, $subject, $message, $headers); } include(‘functions.php’); form(); ?>[/code]

xxx

Use PHP to Mail a Form was last modified: December 4th, 2016 by Maximus Mccullough
use-php-to-mail-a-form

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.