php
  • email
  • html-email
  • mail-form
  • formmail
  • 2017-04-06 2 views 0 likes 
    0

    Je me réfère à cette page. https://bootstrapious.com/p/how-to-build-a-working-bootstrap-contact-form

    je veux mailheader "name"

    mais ce code php est

    <?php 
     
    
     
    // configure 
     
    $from = 'Demo contact form <[email protected]>'; 
     
    $sendTo = 'Demo contact form <[email protected]>'; 
     
    $subject = 'New message from contact form'; 
     
    $fields = array('name' => 'Name', 'surname' => 'Surname', 'phone' => 'Phone', 'email' => 'Email', 'message' => 'Message'); // array variable name => Text to appear in the email 
     
    $okMessage = 'Contact form successfully submitted. Thank you, I will get back to you soon!'; 
     
    $errorMessage = 'There was an error while submitting the form. Please try again later'; 
     
    
     
    // let's do the sending 
     
    
     
    try 
     
    { 
     
        $emailText = "You have new message from contact form\n=============================\n"; 
     
    
     
        foreach ($_POST as $key => $value) { 
     
    
     
         if (isset($fields[$key])) { 
     
          $emailText .= "$fields[$key]: $value\n"; 
     
         } 
     
        } 
     
    
     
        $headers = array('Content-Type: text/plain; charset="UTF-8";', 
     
         'From: ' . $from, 
     
         'Reply-To: ' . $from, 
     
         'Return-Path: ' . $from, 
     
        ); 
     
        
     
        mail($sendTo, $subject, $emailText, implode("\n", $headers)); 
     
    
     
        $responseArray = array('type' => 'success', 'message' => $okMessage); 
     
    } 
     
    catch (\Exception $e) 
     
    { 
     
        $responseArray = array('type' => 'danger', 'message' => $errorMessage); 
     
    } 
     
    
     
    if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { 
     
        $encoded = json_encode($responseArray); 
     
    
     
        header('Content-Type: application/json'); 
     
    
     
        echo $encoded; 
     
    } 
     
    else { 
     
        echo $responseArray['message']; 
     
    }

    donc j'ai essayé

    'formulaire de contact Demo' = $ SENDTO; => mon mail.

    $ from = 'Formulaire de contact de démonstration'; => $ name < '$ email'> mais le résultat est "personne"

    J'ai donc réessayé.

    $headers = array('Content-Type: text/plain; charset="UTF-8";', 
     
         'From: ' . $from, 
     
         'Reply-To: ' . $from, 
     
         'Return-Path: ' . $from, 
     
        );

    =>

    $headers = array('Content-Type: text/plain; charset="UTF-8";', 
     
         'From: ' . $from<$email>, 
     
         'Reply-To: ' . $from, 
     
         'Return-Path: ' . $from, 
     
        );

    Mais il a échoué ...

    Que dois-je faire?

    i essayé

    De: FromName $ et

    $ headers = "A partir de: from_user $ \ r \ n". et

    $ headers. = 'De: "'. $ à partir de '' < '. $ Email. '>'. "\ r \ n"; etc ...

    Répondre

    -1

    Cela a fonctionné pour moi

    $name = strip_tags(htmlspecialchars($_POST['name'])); 
    $email_address = strip_tags(htmlspecialchars($_POST['email'])); 
    
    $from = "$name<$email_address>"; 
    

     Questions connexes

    • Aucun problème connexe^_^