2017-04-04 3 views
0

방문자가 제출 한 답변을 이메일로 보내는 설문지가 웹 사이트에 있습니다. 질문 중 하나는 사용자에게 최상의 접촉 시간 (오전, 오후, 저녁)을 묻습니다. 선택한 클래스의 이름은 접촉 시간입니다.이메일 본문에있는 필드 이름을 바꾸는 방법

현재 이메일 본문에 html 양식에 이름을 지정한 것처럼 연락처 시간으로 표시됩니다. 연락 시간으로 표시하고 싶습니다.

contact-time이라는 선택 클래스에서 값을 가져올 수있는 동안 연락처 시간을 연락처 시간으로 표시하도록 전자 메일의 본문을 작성하려면 어떻게해야합니까? 이 문제와 관련된 모든 질문을 살펴본 결과 관련 정보를 찾을 수 없었습니다. 다음 이메일을 구축하고

PHP 코드는

<form role="form" id="estimateForm" method="POST"> 
    <div class="col-xs-12 contact-information"> 
     <div class="form-group"> 
      <fieldset> 
       <legend>Contact Information</legend> 
       <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6"> 
        <label class="control-label" for="name">Name</label> 
        <input type="text" class="form-control" id="name" name="name" placeholder="Enter Name"> 
        <label class="control-label" for="email">Email</label> 
        <input type="email" class="form-control" id="email" name="email" placeholder="Enter Email"> 
        <label class="control-label" for="address">Address</label> 
        <input type="text" class="form-control" id="address" name="address" placeholder="Enter Address"> 
       </div> 
       <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6"> 
        <label class="control-label" for="phone">Phone Number</label> 
        <input type="tel" class="form-control" id="phone" name="phone" placeholder="Enter Phone Number"> 
        <label class="control-label" for="contact-time">Preferred Contact Time</label> 
        <select class="selectpicker contact-time" id="contact-time" name="contact-time" title="Preferred Contact Time"> 
         <option value="Morning">Morning (9-11am)</option> 
         <option value="Afternoon">Afternoon (11-2pm)</option> 
         <option value="Evening">Evening (2-5pm)</option> 
        </select> 
        <label class="control-label" for="contact-method">Preferred Contact Method</label> 
        <select class="selectpicker contact-method" id="contact-method" name="contact-method" title="Preferred Contact Method"> 
         <option>By Phone</option> 
         <option>By Email</option> 
        </select> 
       </div> 
      </fieldset> 
     </div> 
    </div> 
</form> 

사전에 시간 내 주셔서 감사가

<?php 
    function constructEmailBody() { 
    $fields = array("name" => true, "email" => true, "address" => true, "phone" => true, "contact-time" => true); 
    $message_body = ""; 
    foreach ($fields as $name => $required) { 
     $postedValue = $_POST[$name]; 
     if ($required && empty($postedValue)) { 
     errorResponse("$name is empty."); 
     } else { 
     $message_body .= ucfirst($name) . ": " . $postedValue . "\n"; 
     } 
    } 
    return $message_body; 
    } 

    //attempt to send email 
    $emailBody = constructEmailBody(); 
    require './vender/php_mailer/PHPMailerAutoload.php'; 
    $email = new PHPMailer; 
    $email->CharSet = 'UTF-8'; 
    $email->isSMTP(); 
    $email->Host = 'smtp.gmail.com'; 
    $email->SMTPAuth = true; 
    $email->Username = '[email protected]'; 
    $email->Password = 'MyPassword'; 

    $email->SMTPSecure = 'tls'; 
    $email->Port = 587; 

    $email->setFrom($_POST['email'], $_POST['name']); 
    $email->addAddress('[email protected]'); 
    $email->Subject = 'Estimate Request Answers'; 
    $email->Body = $emailBody; 
    //try to send the message 
    if($email->send()) { 
    echo json_encode(array('message' => 'Thank you! Your message was successfully submitted.')); 
    } else { 
    errorResponse('An unexpected error occured while attempting to send the email: ' . $email->ErrorInfo); 
    } 
?> 

HTML 양식을 보내고 난 어떤 도움을 주셔서 감사합니다.

답변

1

아무것도 당신이에 간단한 str_replace()를 사용할 수있는 메일 코드와 함께 할 수 없습니다 $name

또는

if($name =='whatever'){ 
$name='something else'; 
} 

약 10 다른 옵션