HTML form and PHP Page Help

Hi,
seeing as how this is an off-topic area, is there anyone who would be willing to take a quick look at my HTML form code, and my little 16 line php code - as my website refuses to send me an email from the online html form :frowning:

Been looking at it for hours, but cannot work out why I’m not getting the emails.
If anyone is willing to help, please reply and let me know and I will post the code here.

Any help appreciated.

I could try… send me a private message… But I would suggest using a PHP debugger and stepping through the code… I use NetBeans it is free and works well.

1 Like

Ok - completely at a loss here.

My php code has been checked via an online php checker, and it says the code is fine, but when I try to send the HTML form, the mail.php page displays in the browser, with a blank white screen, and I get no email??

Using php 7.4 (if that helps).

 <?php
    if(isset($_POST['submit'])){
        $to = "myemailaddressgoeshere"; // recipient's Email address
        $name = $_POST['name']; // "name" (form field ID)
        $from = $_POST['email']; // "email" (form field ID)
        $service = $_POST['service']; // "service" (form field ID)
        $stylist = $_POST['stylist']; // "stylist" (form field ID)
        $mainmessagebox = $_POST['mainmessagebox']; // "mainmessagebox" (form field ID)
        $subject = "Website Message";
        $message = "Customer's Name:" . " " . $name . "\n\n" . "Customer's Email:" . " " . $_POST['from'] . "\n\n" . "Service Required:" . " " . $_POST['service'] . "\n\n" . "Stylist:" . " " . $_POST['stylist'] . "\n\n" . "Message:" . " " . $_POST['mainmessagebox'];
        $headers = "From:" . $from;
        $mailOK = mail($to,$subject,$message,$headers);
    if ($mailOK){
    echo "Mail Sent. Thank you " . $name . ", we will contact you shortly to either confirm your appointment, or answer your query.";
    } else {
    echo "Error sending mail";
    };
    };
    ?>

What smtp server are you using? You may need to set one up in your php.ini file.

1 Like

Hi again Jim,

I have only just started paying for a hosting service (1&1 Ionos), and there is no php.ini file that I can see when I use Cyberduck to sftp into my directories.

I guess I need to make one, but have no idea about what goes into it.
Not even sure if I am allowed to upload one? From what I found online - I need to create a simple text file with a .ini extension (php.ini), and then upload it to the same directory as my php mail page.

Problem is I have no idea what lines of code to enter in the file :slight_smile:

You cannot simply implement a php.ini file on a hosted service… the service needs to do it.

I suggest reading through this link for some options: How can I send an email using PHP? - Stack Overflow or email - How to configure PHP to send e-mail? - Stack Overflow