2017-03-06 98 views
-1

我創建了一個使用HTML和PHP的聯繫表格,但我有兩個代碼問題: 第一個:當我按下提交沒有消息發送到我的郵件,我收到此錯誤[第25行錯誤是:郵件($ to,$ subject,$ header,$ body_message);] [1]。聯繫表格PHP和HTML錯誤

二:我得到一個錯誤,當我打開contact.php文件,如圖片中[相關附件這些錯誤] [2]

最後,我想請請,如果任何人都可以給我如何我可以發送附加文件的引用,電子郵件作爲我沒有發現任何幫扶爲

<!doctype html> 
 
<html> 
 
<head> 
 
<meta charset="utf-8"> 
 
<title>Untitled Document</title> 
 
</head> 
 

 
<body> 
 
<h2>Contact Form</h2> 
 
<p><span style="color: red" >*Required field</span></p> 
 
<form action="contact.php" method="post" enctype="multipart/form-data"> 
 
\t First Name:<input type="text" name="fname"><span style="color: red" >*</span><br><br> 
 
\t Last Name:<input type="text" name="lname"><span style="color: red" >*</span><br><br> 
 
\t E-mail:<input type="text" name="email"><span style="color: red" >*</span><br><br> 
 
\t Telephone:<input type="text" name="tel"><br><br> 
 
\t Designation:<select name="design"> 
 
    \t \t <option value="Architectural Engineer">Architectural Engineer</option> 
 
    \t \t <option value="Structural Engineer">Structural Engineer</option> 
 
    \t \t <option value="Draughts-man">Draughts-man</option> 
 
    \t \t <option value="Receptionist">Receptionist</option> 
 
    \t \t <option value="Secertary">Secertary</option> 
 
\t </select><br><br> 
 
\t Country Applied From:<select name="country"> 
 
\t \t <option value="">Country...</option> 
 
\t \t <option value="Afganistan">Afghanistan</option> 
 
\t \t <option value="Albania">Albania</option> 
 
\t \t <option value="Algeria">Algeria</option> 
 
\t \t <option value="American Samoa">American Samoa</option> 
 
</select><br><br> 
 
\t Message:<textarea name="message"></textarea> <br><br> 
 
\t Upload Your Resume:<span style="color: red" >*</span><input type="file" name="uploaded_file"><br><br> \t 
 
\t <input type="submit" name="submit" value="Submit"> 
 
\t <input type="reset" value="clear"> 
 
</form> 
 
</body> 
 
</html>

PHP代碼補充說:

<?php 
 
if(isset($_POST['submit'])){ 
 
$fname = $_POST['fname']; 
 
$lname = $_POST['lname']; 
 
$email = $_POST['email']; 
 
$tel = $_POST['tel']; 
 
$design = $_POST['design']; 
 
$country = $_POST['country']; 
 
$message = $_POST['message']; 
 

 
$to = '[email protected]'; 
 
$subject = 'Contact Form'.$fname; 
 
$header = "$email"; 
 
$body_message = 'From: '.$fname .$lname."\n"; 
 
$body_message .= 'E-mail: '.$email."\n"; 
 
$body_message .= 'Telephone: '.$tel."\n"; 
 
$body_message .= 'Designation: '.$design."\n"; 
 
$body_message .= 'Country Appled From: '.$country."\n"; 
 
$body_message .= 'Message: '.$message."\n"; 
 
\t mail($to, $subject, $header, $body_message); 
 
} 
 

 
$name_of_uploaded_file = basename($_FILES['uploaded_file']['name']); 
 
$type_of_uploaded_file = substr($name_of_uploaded_file, strrpos($name_of_uploaded_file, '.') + 1); 
 
$size_of_uploaded_file = $_FILES["uploaded_file"]["size"]/1048576;//size in MBs 
 
$max_allowed_file_size = 500; // size in KB 
 
$allowed_extensions = array("jpg", "pdf", "docx", "doc"); 
 

 
if($size_of_uploaded_file > $max_allowed_file_size) { 
 
    $errors .= "\n Size of file should be less than $max_allowed_file_size"; 
 
} 
 
//------ Validate the file extension ----- 
 
$allowed_ext = false; 
 
for($i=0; $i<sizeof($allowed_extensions); $i++) 
 
{ 
 
    if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0) { 
 
     $allowed_ext = true; 
 
    } 
 
} 
 
if(!$allowed_ext) { 
 
    $errors .= "\n The uploaded file is not supported file type. ". 
 
" Only the following file types are supported: ".implode(',',$allowed_extensions); 
 
} 
 
?>

+2

**代碼太多**。你需要更好地解決這個問題。我們不是*調試器。您需要**隔離問題**並從那裏進行調試。如果您遇到困難,請使用[** Minimal,Complete和Verifiable示例**](http://stackoverflow.com/help/mcve)提供**清楚說明不工作的**。我建議閱讀[問]一個好問題和[完美問題](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/)。另外,一定要參加[旅遊]。 –

回答

0

它看起來像它不工作的原因是,你有郵件和標題才能在PHP郵件功能混合起來。

您採寫:

mail($to, $subject, $header, $body_message); 

正確的格式: 郵件($到,$主題,$ body_message,$頭);

PHP郵件()

bool mail (string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]]) 

http://php.net/manual/en/function.mail.php

0

您的電子郵件代碼應該如下: -

$to  = '[email protected]'; 
$subject = 'the subject'; 
$message = 'hello'; 
$headers = 'From: [email protected]' . "\r\n" . 
    'Reply-To: [email protected]' . "\r\n" . 
    'X-Mailer: PHP/' . phpversion(); 

$isSuccess = mail($to, $subject, $message, $headers); 

if($isSuccess == true) { // if mail is successfully sent 
    echo "Message sent successfully..."; 
}else{ 
    echo "Message could not be sent..."; 
} 

閱讀documentation瞭解更多詳情。