2017-12-28 2 views
0

私はhtmlページからPHPにデータを持ち込むことができませんでした。私は一日中それをテストしていましたが、私はこの問題に固執しています。手伝っていただけませんか?どうもありがとうございます。以下は私のコード....htmlのデータがphpファイルに表示されず空のメールとして送信される

service.htmlのある

<div class="accordion-inner"> 
    <div class="status alert alert-success" style="display: none"></div> 
    <form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="requestquote.php" role="form"> 
    <div class="row-fluid"> 
     <div class="span5" style="text-align: left;"> 
     <label>FULL NAME</label> 
     <input type="text" name="fname" id="fname" class="input-block-level" required="required" placeholder="Your Full Name" tabindex="1"> 
     <label>COMPANY (OPTIONAL)</label> 
     <input type="text" name="cname" id="cname" class="input-block-level" placeholder="Your Company Name" tabindex="2"> 
     <label>EMAIL </label> 
     <input type="text" name="email" id="email" class="input-block-level" required="required" placeholder="Your Email Address" tabindex="3"> 
     <label>PHONE</label> 
     <input type="text" name="phone" id="phone" class="input-block-level" required="required" placeholder="Your Phone" tabindex="4"> 
     </div> 
     <div class="span7" style="text-align: left;"> 
     <label>SOLUTIONS</label> 

     <select name="category" id="category">         
             <option value="">Please Select…</option> 
             <option value="Web Design and Development">Web Design and Development</option> 
             <option value="Mobile Application Development">Mobile Application Development</option> 
             <option value="Networking Services & Consultancy">Networking Services &amp; Consultancy</option> 
             <option value="Hotel Management Solution ">Hotel Management Solution </option>         
             <option value="IT Help Desk Service ">IT Help Desk Service </option> 
            </select> 
     <label>YOUR IDEAS (OR) MESSAGE </label> 
     <textarea name="message1" id="message1" required="required" class="input-block-level1" rows="10" tabindex="5"></textarea> 
     </div> 

    </div> 
    <input type="submit" name="sendmsg" class="btn btn-primary btn-large pull-right" value="Send Message"> 
    </form> 
</div> 
</div> 

requestquote.php

<?php 

header('Content-type: application/json'); 
$status = array(
    'type'=>'success', 
    'message'=>'Thank you for contacting us!, ' 
); 

$fname = @trim(stripslashes($_POST['fname'])); 
$cname = @trim(stripslashes($_POST['cname'])); 
$email = @trim(stripslashes($_POST['email'])); 
$phone = @trim(stripslashes($_POST['phone'])); 
$category = @trim(stripslashes($_POST['category']));   
$message1 = @trim(stripslashes($_POST['message1'])); 

$email_from = $email; 
$email_to = "[email protected]"; 

$from = "[email protected]"; 
$headers = "From:" . $from; 

$Body = 'First Name: ' . $fname . "\n \n " .'Company Name: ' . $cname . "\n\n" . 'Email: ' . $email . "\n\n" . 'Phone: ' . $phone . "\n\n" . 'category: ' . $category . "\n\n" . 'Message: ' . $message1; 

$success = @mail($email_to,"Request a free quotation", $Body, $headers); 

$thankyou = "Thank you for contacting us. We will be in touch with you shortly."; 
@mail($email_from," Request a free quotation ", $thankyou, $headers); 


if($success == true){ 
     echo json_encode($status); 
     die; 
} else { 
     echo json_encode(" Failed "); 
} 

>

+0

https://stackoverflow.com/questions/29815710/why-is-phps-mail-function-successfully-sending-mail-but-with-空白フィールド – claudio

+0

これは以下のようなものです:header( 'Content-type:application/json'); – halojoy

+0

あなたはエラーを甘やかすべきではありません:@mail($ email_fromはメールのようにベターです($ email_from – halojoy

答えて

0

代わりに$headers変数のこれを使用してください:?

// To send HTML mail, the Content-type header must be set 
$headers[] = 'MIME-Version: 1.0'; 
$headers[] = 'Content-type: text/html; charset=iso-8859-1'; 

// Additional headers 
$headers[] = 'From: ymphyow <[email protected]>'; 

チェックSource

も同様の質問を確認してくださいWhy is php's mail() function successfully sending mail but with blank fields?

+0

私は試しましたが、今まで動作しません) – Max

+0

代わりにそれらのヘッダーを試してください $ headers $ headers []。= "コンテンツタイプ:multipart/alternative; \ r \ n"; 私はちょうど試して、完全に動作し、あなたのように思えます。 )\ r \ nが必要です;) –

+0

とエラーを抑制するために@を使用しないでください –

関連する問題