0

I have two files: trips.hbs and email.php:

trips.hbs:

<!DOCTYPE html>

<html lang="en">
<head>
    <title>{{#if data.trip}}{{data.trip.title}}{{/if}}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="/styles/custom/trip.css">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <script>
        function showDiv () {
            let order = document.getElementById("order");
            if (order.style.display === 'flex') {
                order.style.display = 'none';
            } else {
                order.style.display = 'flex';
            }
        }
    </script>
</head>
<body>
    {{#if data.trip}}
        <div class="container" style="background: url('{{ cloudinaryUrl data.trip.coverImage }}') center no-repeat; background-size: cover; ">
            <div class="tour">
                <div class="content">
                    <h1 class="title">{{data.trip.title}}</h1>
                    <div class="info">
                        <p class="item">Duration: <br>{{data.trip.duration}}</p>
                        <p class="item">Distance: <br>{{data.trip.distance}}</p>
                        <p class="item">Price: <br>{{data.trip.price}}€</p>    
                    </div>
                    {{#if data.trip.content.additional}}
                        <div class="additional">
                            <p>{{{data.trip.content.additional}}}</p>
                        </div>
                    {{/if}}
                </div>
            </div>
        </div>
        <div class="extended">
            <p class="text">{{# if data.trip.content.extended }} {{{data.trip.content.extended}}} {{/if}}</p>
        </div>
        <div class="photos">
            {{#each data.trip.images }}
                <img src="{{cloudinaryUrl}}" class="list-photo" alt="{{../data.trip.title}} Photo">
            {{/each}}
        </div>
        <div class="order-container">
            <button class="order" onclick="showDiv()">Order</button>
            <div id="order" class="order-form">
                <h1 class="form-title">Order</h1>
                <form 
                        class="form-container" 
                        id="order-trip-form" 
                        name="simple-contact-form" 
                        accept-charset="utf-8" 
                        action="email.php" 
                        method="post"
                >
                    <div class="input-1">
                        <input class="input name" type="text" name="name" placeholder="Name" required="required">
                        <input class="input email" type="email" name="email" placeholder="Email" required="required">
                        <input class="input phone" type="text" name="phone" placeholder="Phone (Optional)" required="">
                        <input class="input number" type="number" name="number" placeholder="Number of people" required="required">
                    </div>
                    <div class="input-2">
                        <input class="input place" type="text" name="place" placeholder="Place to meet" required="required">
                        <input class="input date" type="date" name="date" placeholder="Date" required="required">
                        <textarea class="comments" name="comments" placeholder="Any comments" required=""></textarea>
                    </div>
                    <div class="submit-buttons">
                        <input type="hidden" name="_subject" id="email-subject" value="Contact Form Submission">
                        <input type="submit" name="submit" value="Submit" class="submit" id="submit">
                    </div>
                </form>
            </div>
        </div>
    {{/if}}
</body>
</html>

email.php:

<?php
    if($_POST["submit"]) {
        $to="retvizanjr@gmail.com";
        $subject="Order submission";
        $name=$_POST['name'];
        $from=$_POST['email'];
        $phone=$_POST['phone'];
        $number=$_POST['number'];
        $place=$_POST['place'];
        $date=$_POST['date'];
        $message=$_POST['comments'];

        $headers =  "Name: $name\n
                     Email: $from\n
                     Phone: $email\n
                     Number of people: $number\n
                     Place to meet: $place\n
                     Date: $date"    
        mail($to,$subject,$message,$headers);
    }
?>

I've created form that I need to send by email, but this code doesn't send email.

  • "doesn't work" _in what way_? What _does_ happen? What debugging have you already done? – Patrick Q Apr 08 '20 at 12:26
  • FYI, the [additional_headers](https://www.php.net/manual/en/function.mail.php) argument is not for what you seem to think it is. – Patrick Q Apr 08 '20 at 12:28
  • @PatrickQ sorry, I've edited my question. Specifically, this code doesn't send any email. – Michael Shkarubski Apr 08 '20 at 12:39
  • Again, _what debugging have you done_? Are you sure that it's actually not _sending_ the email or just that you are not _receiving_ the email? If it really isn't sending, then do you know that the line of code that does the sending is actually being reached? – Patrick Q Apr 08 '20 at 12:51
  • @PatrickQ I haven't received any emails. How can it be possible not to receive email if the email sent and my email address is correct? I haven't faced PHP till that moment so I absolutely don't know why this code doesn't work – Michael Shkarubski Apr 08 '20 at 13:06
  • There are myriad reasons why a sent email would not be received. Please check the linked duplicate. But the first thing you need to do is confirm that your code is even getting to the point where the email is attempted. We can't do your debugging for you. – Patrick Q Apr 08 '20 at 13:26

0 Answers0