Home > database >  Send HTML in email via PHP with datepicker values
Send HTML in email via PHP with datepicker values

Time:09-29

I want to have a page with some form inputs and with date picker i want to send these all fields to mail how to i do this with PHP?

CodePudding user response:

You can do that by first getting what users typed in a form. Then parse the input into a text file or html file that you can send using the mail() function in PHP.

for example for a "datepickerfield" field:

<?php
$to      = '[email protected]';
$subject = 'the subject';
$message = $_GET['datepickerfield'];
$headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

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

CodePudding user response:

You can access the form input fields in PHP over $_GET or $_POST. This depends on your form.

<form action="/mail.php" method="get">

or

<form action="/mail.php" method="post">

Here's an example:

HTML Form:

<form action="/mail.php" method="post">
  <label for="fullname">Full name:</label>
  <input type="text" id="fullname" name="fullname">
  <label for="birthday">Birthday:</label>
  <input type="date" id="birthday" name="birthday">
  <input type="submit" value="Submit">
</form>

and in your php file :

<?php
$to      = '[email protected]';
$subject = 'the subject';
$headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();


$message = 'The Birthday of '.$_POST['fullname'].' is: '.$_POST['birthday'];

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

Take a look at https://www.php.net/manual/en/function.mail.php

  • Related