0

So i have my code and styling finished, first it worked tried a few times and it was sending mails. the next day it was not sending any more, testing this on live server no localhost.

i need this code to work so clients can ask for information and we give them offers. i have read it is better to use request method but have never used it, but if this may be a solution i will try it.

This is a test version of the website https://www.two4u.be/test/index.php?page=contact

searching for a few days what the problem could be.

<?php 
    // email info to send
    $to = "sammy@two4u.be"; // this is your Email address
    $subject = "Offerte aanvraag website";
    $from = $_POST['email']; // this is the sender's Email address
    $name = $_POST['name'];
    $straat = $_POST['straat'];
    $gemeente = $_POST['gemeente'];
    $nummer = $_POST['nummer'];
    $tijdstip = $_POST['tijdstip'];
    $systeemkeuze = $_POST['systeemkeuze'];
    $budget = $_POST['budget'];
    $termijn = $_POST['termijn'];
    $extra = $_POST['extra'];

    // create email headers
    $headers = "From: Two 4 U <noreply@two4u.be>\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=iso-8859-1\n";

    // create the html message
    $message = "<html>
        <body>
            <h1> Offerte aanvraag via website</h1>
            <h2> Gegevens van de klant</h2>
            <p> <b>email:</b> $from <br>
            <b>naam:</b> $name <br>
            <b>Adres:</b> $gemeente <br>
            $straat<br>
            <b>Telefoon:</b> $nummer<br>
            <b>Wanneer klant bereikbaar is:</b> $tijdstip<br>
            <b>Welk systeem van ons:</b> $systeemkeuze<br>
            <b>Klant budget hiervoor:</b> $budget<br>
            <b>Binnen welke termijn:</b> $termijn<br>
            </p>
            <p> <b>Extra informatie:</b> $extra </p>
    
    </body></html>";
    
    // send email to user  
    if (!empty($_POST['mail'])){
        mail($to, $subject, $message, $headers);
    }    
?>
  • 3
    Read through the main answer at this link, and at some point, if you follow all the guidance and check everything thoroughly, you should discover the issue: [PHP mail function doesn't complete sending of e-mail](https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail). Remember also that an email can be successfully _sent_, but that does not in any way guarantee that it will be successfully _received_. It's an important distinction. First step is, you need to ascertain whether the emails are failing to send, or merely failing to arrive. – ADyson Jan 03 '22 at 00:59

1 Answers1

0

In your submission form, there is no input box with the name="mail", Hence change


 if (!empty($_POST['mail'])){
        mail($to, $subject, $message, $headers);
    }    

to

 if (!empty($_POST['email'])){
        mail($to, $subject, $message, $headers);
    }    

Ken Lee
  • 6,985
  • 3
  • 10
  • 29