0
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>

<form method="POST" action="mail.php">

<div class="row">
    <div class="col-sm-6">
        <?php echo $company ?>
    </div>
    <div class="col-sm-6">
        <?php echo $city ?>
    </div>
</div>
<div class="row">
    <div class="col-sm-6">
        <?php echo $name ?>
    </div>
    <div class="col-sm-6">
        <?php echo $second_name ?>
    </div>
</div>
<div class="row">
    <div class="col-sm-6">
        <?php echo $phone ?>
    </div>
    <div class="col-sm-6">
        <?php echo $email ?>
    </div>
</div>

<?php echo $message ?>
<div style="font-family: Arial; font-size: 14px; line-height:18px; color: #000000; margin: 0; padding: 0; text-align: justify; text-justify: inter-word;">
<input type="hidden" name="deal" id="deal" value="Nu">
<input type="checkbox" name="deal" id="deal" value="Yes"> I agree.<br>
</div>
<div class="clearfix"><button class="btn-green pull-right" type="submit">Trimite</button></div>
</form>

and the mail.php

nie<?php

if ($_SERVER['REQUEST_METHOD'] === 'POST') {

    // Retrieve data from the form
    $companie = $_POST['company'];
    $localitate = $_POST['city'];
    $nume = $_POST['name'];
    $prenume = $_POST['second_name'];
    $telefon = $_POST['phone'];
    $email = $_POST['email'];
    $mesaj = $_POST['message'];

    // Check if the checkbox is checked
    if (isset($_POST['acord']) && $_POST['acord'] === 'Da') {

        // Construct the email message
        $to = 'test@gmail.com';
        $subject = 'New Maessage';
        $message = "Company: $company\nCity: $city\nName: $name\nSecond_name: $second_name\nPhone: $phone\nEmail: $email\nMessage: $message";

        // Send the email
        if (mail($to, $subject, $message)) {
            echo 'Mail send ok';
        } else {
            echo 'Error sending email';
        }
    } else {
        // Show error message if the checkbox is not checked
        echo 'Please agree with the following';
    }
}
?>

Hello,

I want to sent email using the form bellow but I receive a blank page and I really dont know why. Ive added even the mail.php file and nothing seems to be wrong but I cannot find the bug in order to send an email when I press the Submit button. I should receive an email on my email address, but I did not receive anything, only a blank page and it`s not ok.

Thank you. Mihaita

  • Is the email blank, or is the webpage blank? The variables in your `$message` do not match the variables you created from the POST values. – aynber May 10 '23 at 11:58
  • the webpage is blank – Mihaita May 10 '23 at 12:01
  • 1
    The *only* inputs you have on your first script are a hidden input named `deal`, and a checkbox with the exact same name, plus your submit button. There are no inputs for any other value. Divs are not inputs. – aynber May 10 '23 at 12:15
  • I`ve added the imputs for all of that fields but I receive the same blank page... – Mihaita May 10 '23 at 12:58
  • Check your server error logs for any errors. If there are no errors there, try following the suggestions [on this link](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display). If there are no errors, try adding some debugging lines in your script, such as `echo "Got to line ".__LINE__."\n";` at various places in your script to see where it's going. – aynber May 10 '23 at 13:15

0 Answers0