1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 5.00 out of 5)

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.

Tip: Click on images to make them larger. If you find anything wrong on this page or need further assistance please comment below or contact me. 🙂
<?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>

';
}

?>

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.

<?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: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); } include('functions.php'); form(); ?>

xxx

Subscribe To My YouTube Channel:
Use PHP to Mail a Form was last modified: December 4th, 2016 by Maximus Mccullough

Please like, share and subscribe.

Advanced Programming Made Easy

I hope you enjoyed the article. If I was able to help you please consider a tip for the content.

One Time Tip

more tips

Reoccuring Tips

Tips

Cool People Share:
use-php-to-mail-a-form

Leave a Reply

Your email address will not be published. Required fields are marked *

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