2016-09-10 2 views
0

Итак, у меня эта форма оформлена, и она настроена на мой адрес электронной почты. Форма отправляется, но она показывает только два нижних поля в письмах. Как видно из приведенного ниже кода, есть 5 полей. Как я могу сделать, где я получу информацию для всего поля?Определенный FormFiled не в теле письма

HTML:

<form id="ajax-contact" method="post" action="../js/mailer.php"> 

        <div class="field">           
         <select id="select" name="interest" title="Interested in ..." class="selectpicker"> 
          <option value="NA">Interested in...</option> 
          <option value="Website">Website</option> 
          <option value="Web Design"> Only Web Design</option> 
          <option value="Brand Consulting">Brand Consulting</option> 
         </select> 
        </div> 

        <div class="field"> 
         <input name="name" placeholder="Name:" type="text" id="name" required> 
        </div> 

        <div class="field"> 
         <input name="email" placeholder="Email: " type="email" id="email"required> 
        </div> 
    <div class="field"> 
        <div class="wrapper"> 
         <label><p>Budget:</p></label> 
         <div id="radio" class="toggle_radio"> 
         <input value="$4k" type="radio" class="toggle_option" id="first_toggle" name="budget"> 
         <input value="$5k - $9k" type="radio" checked class="toggle_option" id="second_toggle" name="budget"> 
         <input value="$10k+" type="radio" class="toggle_option" id="third_toggle" name="budget"> 

         <label for="first_toggle"><p>>$4k</p></label> 
         <label for="second_toggle"><p>$5k - $9k</p></label> 
         <label for="third_toggle"><p>$10k+</p></label> 
         <div class="toggle_option_slider"> 
         </div> 
         </div> 
        </div> 
    </div> 

<div class="field"> 
      <textarea placeholder="project description(optional)" id="message" name="message" required></textarea> 
</div> 

<div class="field"> 
    <button id="button" type="submit">SEND REQUEST</button> 
</div> 
</form> 

PHP:

<?php 
// My modifications to mailer script from: 
// http://blog.teamtreehouse.com/create-ajax-contact-form 
// Added input sanitizing to prevent injection 

// Only process POST reqeusts. 
if ($_SERVER["REQUEST_METHOD"] == "POST") { 
    // Get the form fields and remove whitespace. 
    $option = $_POST['interest']; 
    $name = $_POST['name']; 
    $email = $_POST['email']; 
    $rdb_value = $_POST['budget']; 
    $message = trim($_POST["message"]); 

    // Check that data was sent to the mailer. 
    if (empty($name) OR empty($message) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) { 
     // Set a 400 (bad request) response code and exit. 
     http_response_code(400); 
     echo "Oops! There was a problem with your submission. Please complete the form and try again."; 
     exit; 
    } 

    // Set the recipient email address. 
    // FIXME: Update this to your desired email address. 
    $recipient = "EMAIL GOES HERE"; 

    // Set the email subject. 
    $subject = "New Request from: $name"; 

    // Build the email content. 
    $email_content = "Interested in: $option\n"; 
    $email_content = "Name: $name\n"; 
    $email_content .= "Email: $email\n\n"; 
    $email_content = "Budget: $rdb_value\n"; 
    $email_content .= "Message:\n$message\n"; 

    // Build the email headers. 
    $email_headers = "From: $name <$email>"; 

    // Send the email. 
    if (mail($recipient, $subject, $email_content, $email_headers)) { 
     // Set a 200 (okay) response code. 
     http_response_code(200); 
     echo "Thank You! Your message has been sent."; 
    } else { 
     // Set a 500 (internal server error) response code. 
     http_response_code(500); 
     echo "Oops! Something went wrong and we couldn't send your message."; 
    } 

} else { 
    // Not a POST request, set a 403 (forbidden) response code. 
    http_response_code(403); 
    echo "There was a problem with your submission, please try again."; 
} 

?> 

ответ

2

Вы видите недостающие сцепляются/точки здесь?

// Build the email content. 
$email_content = "Interested in: $option\n"; 
$email_content = "Name: $name\n"; 
      ^there 
$email_content .= "Email: $email\n\n"; 
$email_content = "Budget: $rdb_value\n"; 
      ^and there 
$email_content .= "Message:\n$message\n"; 

Это сломало «цепочку».

Добавьте их:

// Build the email content. 
$email_content = "Interested in: $option\n"; 
$email_content .= "Name: $name\n"; 
$email_content .= "Email: $email\n\n"; 
$email_content .= "Budget: $rdb_value\n"; 
$email_content .= "Message:\n$message\n"; 
+0

Это ... РАБОТАЛ !!!! Огромное спасибо!!!!! Я поднял ваш голос, но я недостаточно хорош, чтобы изменить его публично. – ethanfox27

+0

@ ethanfox27 Добро пожаловать. Я знаю, что вы не можете повышать прямо сейчас (спасибо в любом случае), но вы можете принять ответ, чтобы отметить вопрос как решаемый ;-) –

+0

@ ethanfox27 Вот как вы это делаете http://meta.stackexchange.com/questions/5234/how-do-accepting-a-answer-work, тогда вернитесь сюда и выполните то же самое. Это официально означало бы ваш вопрос как решаемый. –

Смежные вопросы