2014-06-13 61 views
0

我寫過一個php腳本,它將表單中的數據保存在mysql數據庫中,並在發送郵件後發送郵件。數據保存在數據庫中,併發送電子郵件,但我沒有在收件箱中收到它。我是新來的PHP,不知道是什麼導致這一點。請幫忙。已發送PHP郵件,但未收到收件箱

<?php 
include ('regdb_conn.php'); 

if (isset($_POST['submit'])){ 

$companyname = $_POST['companyname']; 
$pAddress = $_POST['pAddress']; // required 
$lAddress = $_POST['lAddress']; // required 
$telno4 = $_POST['telno4']; // required 
$faxno4 = $_POST['faxno4']; // required 
$email4 = $_POST['email4']; 
$trade = $_POST['trade']; 
$business = $_POST['business']; 
$noEmployee = $_POST['noEmployee']; 
$designation = $_POST['designation']; 
$hr = $_POST['HR']; 
$retainer_fee_1 = $_POST['retainer_fee_1']; 
$retainer_fee_2 = $_POST['retainer_fee_2']; 
$from_date = $_POST['from_date']; 
$to_date = $_POST['to_date']; 

$sql="INSERT INTO subscription(company_name,postal_address,location_address, 
    telephone,fax,email,trade_union_workmen,nature_of_business,total_employee, 
    details_newsletter,name_head_hr,retainer_fee_1,retainer_fee_2,from_date,to_date) 
VALUES('$companyname','$pAddress','$lAddress','$telno4','$faxno4','$email4', 
    '$trade','$business','$noEmployee','$designation',         
'$hr','$retainer_fee_1','$retainer_fee_2','$from_date','$to_date')"; 

$result = mysql_query($sql); 

if($result) { 
      echo "Data Successfully saved in database subscription!"; 
     } 
else   { 
      echo "ERROR, data was not saved or email was not sent"; 
     } 


    $emailID = "[email protected]"; 
    $subject = "New Subcription form submitted from. $companyname . through our website"; 

    $body = <<<EOD 

    <table cellspacing="0" cellpadding="1" border="1"> 
     <tbody> 
      <tr> 
       <td style="padding: 5px 10px;" width="150">Company Name: </td> 
       <td style="padding: 5px 10px;">$companyname</td> 
      </tr> 
      <tr> 
       <td style="padding: 5px 10px;" width="150">Telephone No: </td> 
       <td style="padding: 5px 10px;">$telno4</td> 
      </tr> 
      <tr> 
       <td style="padding: 5px 10px;" width="150">Email: </td> 
       <td style="padding: 5px 10px;">$email4</td> 
      </tr> 
      <tr> 
       <td style="padding: 5px 10px;" width="150">Fax No: </td> 
       <td style="padding: 5px 10px;">$faxno4</td> 
      </tr> 
     </tbody> 
    </table>  
EOD; 

    $headers = "From:" .$email4. "\r\n"; 
    $headers .= "MIME-Version: 1.0\r\n"; 
    $headers .= "Content-Type: text/html; charset=\"iso-8859-1\"\n"; 
    $headers .= "X-Priority: 1\r\n"; 
    $headers .= "X-MSMail-Priority: High\n"; 
    $headers .= "X-Mailer: PHP". phpversion() ."\r\n"; 

    mail($emailID, $subject, $body, $headers); 
    echo "<h4>Thank you for sending us an enquiry. We will get back to you.</h4>"; 

} else { 
    echo("Kindly use the form to submit the data!"); 
}; 
?> 
+1

檢查了垃圾郵件文件夾? – shatheesh

+3

也檢查電子郵件是否實際發送'if(mail($ emailID,$ subject,$ body,$ headers)){echo「sent」;}' – UserProg

+0

@UserProg你是對的..我只是認爲它。 – shatheesh

回答

-2
Try using \n instead of \r\n. 

     OR 

    you could use the PHP_EOL constant 

     OR 

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

$headers .= 'To: Person <[email protected]>' . "\r\n"; 
$headers .= 'From: My Name <[email protected]>' . "\r\n"; 
$headers .= 'Cc: ' . "\r\n"; 
$headers .= 'Bcc: ' . "\r\n"; 
+0

這與它爲什麼不起作用無關 – hank

1

試試這個代碼:

if(mail($emailID, $subject, $body, $headers)){ 
    echo "<h4>Thank you for sending us an enquiry. We will get back to you.</h4>"; 
} 
else{ 
    echo "<h4>Mail sending fail.</h4>"; 
} 
+0

我已經使用了if else條件,電子郵件已發送,但沒有收到我的收件箱 – user1930115

相關問題