Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Nicholas Lee
Nicholas Lee
12,474 Points

How to pass user selected date and time to php mailer?

Similar to the contact page of the PHP shirt store project I am trying to pass a user selected time and date.

For the time I used this.

<tr>
                    <th>
                            <label for="eventtime">Time of Event:</label>
                    </th>
                    <td>
                            <input type="time" name="eventtime"      id="eventtime" value="12:00:00" >
                     </td>
</tr>

And for the date

<tr>
                    <th>
                            <label for="eventdate">Date of Event:</label>
                    </th>
                    <td>
                            <input type="date" name="eventdate" id="eventdate" value="1/1/2020" >
                    </td>
</tr>

On my website the html selector shows up but it does not ended up sending to my email.

I tried to store it like such:

$email_body = $email_body . "Event Date" . $eventdate. "<br>";
$email_body = $email_body . "Event Time" . $eventtime. "<br>";     

and

$eventdate = trim($_POST["eventdate"]);
$time = trim($_POST["time"]);

And send it along with phpmailer

$mail->MsgHTML($email_body);

Does anyone have any tips on how to accomplish this?

2 Answers

Nicholas Lee
Nicholas Lee
12,474 Points

I got it to work using this.

<input type="text" name="eventdate" value="<?php echo date('Y-m-d'); ?>" />
Nicholas Lee
Nicholas Lee
12,474 Points

I am having trouble with the time however.

Nicholas Lee
Nicholas Lee
12,474 Points

I am using this for time but it fail to store it.

<input type="text" name="eventtime" id="eventtime" value= "<?php echo date('h-i'); ?>"/>