Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End sendmail php doesn't work

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #274760
    giovannicrazy
    Participant

    I create a simple form with sendmail but it doesn’t work and I do not know why.

    Here is the code:

    <?php
    if ($_SERVER["REQUEST_METHOD"] == "POST")
    {
        $nome = $_POST['nome'];
        $cognome = $_POST['cognome'];
        $telefono = $_POST['telefono'];
        $email = $_POST['email'];
        $sede = $_POST['sede'];
        $sede1 =$_POST['sede1'];
        $corso = $_POST['corso'];
        $corso_abbinato = $_POST['corso_abbinato'];
        $corso = $_POST['corso'];
        $messaggio = $_POST['messaggio'];
    
        if (!filter_var($email, FILTER_VALIDATE_EMAIL))
        {
            echo 'Inserire un indirizzo valio per l\'email';
            exit();
        }
    
    
        switch ($sede1) {
            case 'ITFI01':
                $recipient ='[email protected]';
                break;
            case 'ITRM01':
                $recipient ='[email protected]';
                break;
            case 'ITNA01':
               $recipient ='[email protected]';
                break;
            case 'ITTO01':
                $recipient ='[email protected]';
                break;
            case 'ITBS01':
                $recipient ='[email protected]';
                break;
            case 'ITRE01':
                $recipient ='[email protected]';
                break;
            case 'ITPD01':
                $recipient ='[email protected]';
                break;
            case 'ITPE01':
                $recipient ='[email protected]';
                break;
            case 'ITGE01':
                $recipient ='[email protected]';
                break;
    
            default:
                $recipient ='[email protected]';
        }
    
        // Your e-mailadress.
      //  $recipient = "[email protected]";
        // Mail subject
        $subject = '=?UTF-8?B?' . $subject . '?=';
        $subject = 'Mail da website scuolacomics.com';
        // Mail content
        $email_content = 'Nome: ' . $nome .
        "\r\n".'Cognome: ' . $cognome .
        "\r\n".'Email: ' . $email .
        "\r\n".'Telefono: ' . $telefono .
        "\r\n".'Sede: ' . $sede .
        "\r\n".'Corso: ' . $corso .
        "\r\n".'Messaggio: ' . utf8_decode($messaggio);
        // Mail headers
        $email_headers= "From: $nome <$email>\r\nMIME-Version: 1.0\r\nContent-Type: text/plain;charset=utf-8";
        // Main messages
        if (mail($recipient, $subject, $email_content, $email_headers))
        {
            echo "Richiesta inviata con successo !";
        }
        else
        {
            echo "Oops! Qualcosa è andato storto e non possiamo processare la tua richiesta";
        }
    }
    else
    {
        echo "Si è verificato un problema con l'invio, riprova.";
    }
    
    ?>
    
    #274772
    Beverleyh
    Participant

    We can’t comment on why the POST variables from the actual form don’t work because you haven’t provided your HTML, but the PHP mail() aspect works fine in a PHP page hosted on “mywebsite.com”, with SMTP enabled on the server, using a send-email address associated with “mywebsite.com”.

    Tested using this part of your script;

    $nome = 'ME';
    $email = '[email protected]';
    
        // Your e-mailadress.
        $recipient = "[email protected]";
        // Mail subject
        $subject = 'Mail da website scuolacomics.com';
        // Mail content
        $email_content = 'TEST MESSAGE';
        // Mail headers
        $email_headers= "From: $nome <$email>\r\nMIME-Version: 1.0\r\nContent-Type: text/plain;charset=utf-8";
        // Main messages
        if (mail($recipient, $subject, $email_content, $email_headers))
        {
            echo "Richiesta inviata con successo !";
        }
        else
        {
            echo "Oops! Qualcosa è andato storto e non possiamo processare la tua richiesta";
        }
    
    #274782
    giovannicrazy
    Participant

    I have 2 different page with same form but one sendmail.php, is it a problem?

    #274783
    giovannicrazy
    Participant

    Here is the html code:

    <form action="" method="post" id="MyForm">
    
                        
    </form>

    and here is the script code in html:

    “`

    $(function() {

    $(‘[name=send]’).on(‘click’,
    function(e){

        // var sede = $('#sede option:selected').text();
        // var sede1 = $('#sede option:selected').val();
      //  var corso = $('[name=corso]').val();
      //  var corso_abbinato = $('[name=corso_abbinato]').val();
        // var corso  = $('[name=titolo_studio]').val();
        var nome = $('#nome').val();
        var cognome = $('#cognome').val();
        var email = $('#email').val();
        var tel = $('#telefono').val();
        var mex = $('#message').val();
    
        //Testo
        var re = /[A-Za-z -']$/;
        if(re.test(document.getElementById("nome").value)){
          console.log("Nome valida");
          document.getElementById("nome").style.border ='1px solid #3c8f1b';
          validation_name = 1;
        }else{
          console.log("Nome non valido");
          document.getElementById("nome").style.border ='1px solid #c30000';
          validation_name = 0;
        }
    
        if(re.test(document.getElementById("cognome").value)){
          console.log("Cognome valida");
          document.getElementById("cognome").style.border ='1px solid #3c8f1b';
          validation_surname = 1;
        }else{
          console.log("Cognome non valido");
          document.getElementById("cognome").style.border ='1px solid #c30000';
          validation_surname = 0;
        }
    
    
        //Email
        var checkEmail = email.match(/^[a-zA-Z0-9.!#$%&amp;'*+/=?^_`{|}~-][email protected][a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/);
        console.log(checkEmail);
        if(checkEmail){
          console.log("Email valida");
           document.getElementById("email").style.border ='1px solid #3c8f1b';
           validation_email = 1;
         } else {
           console.log("Email non valida");
           document.getElementById("email").style.border ='1px solid #c30000';
           validation_email = 0;
         }
    
        //Validazione
        if(validation_email == 1 &amp;&amp; validation_name == 1 &amp;&amp; validation_surname == 1){
            $.post( "/sendmail-roma.php", {
            nome: nome,
            cognome: cognome,
            email: email,
            telefono: tel,
            // sede: sede,
            // corso: corso,
            messaggio: mex,
            // sede1: sede1
            })
            .done(function( data ) {
                alert(data);
             //   console.log(data);
            })
            .fail(function() {
                console.log( "error" );
            });
        }
        else {
            console.log("Validazione non superata");
        }
    
        e.preventDefault();
    
    
    
    });
    

    });

    “`

    #274784
    giovannicrazy
    Participant

    <form action="" method="post" id="MyForm">
    </form>
Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Back End’ is closed to new topics and replies.