2013-08-01 92 views
0

我需要一個讓我的PHP郵件功能正常工作的小手。PHP郵件功能 - 需要幫助

這是我現在有,我的PHP文件的標題中:

<?php 
require_once('common.php'); 

require_once('mailer.php'); 

if (isset($_POST['submitBtn'])) 
{ 
    // Get user input 
    $conName = isset($_POST['conName']) ? $_POST['conName'] : ''; 
    $conEmail = isset($_POST['conEmail']) ? $_POST['conEmail'] : ''; 
    $conPhone = isset($_POST['conPhone']) ? $_POST['conPhone'] : ''; 
    $conNatureof = isset($_POST['conNatureof']) ? $_POST['conNatureof'] : ''; 
    $conSubject = isset($_POST['conSubject']) ? $_POST['conSubject'] : ''; 
    $conMessage = isset($_POST['conMessage']) ? $_POST['conMessage'] : ''; 

    // Try to send the email 
    $error = sendMail($conName,$conEmail,$conPhone,$conNatureof,$conSubject,$conMessage); 
} 
?> 

這是目前我的PHP文件的正文中:

<?php if ((!isset($_POST['submitBtn'])) || ($error != '')) {?> 
<form method="post" action="contact.php" enctype="multipart/form-data"> 

<p><label for="conName">Name:<span class="required">*</span></label><input name="conName" id="conName" type="text" class="input"/></p> 
<p><label for="conEmail">Email:<span class="required">*</span></label><input name="conEmail" id="conEmail" type="text" class="input" /></p> 
<p><label for="conPhone">Phone:</label><input name="conPhone" id="conPhone" type="text" class="input" /></p> 
<p><label for="conNatureof">Nature of enquiry:<span class="required">*</span></label> 
<select name="conNatureof" class="input" id="conNatureof"> 
    <option value="-">-- Please Select --</option> 
    <option value="interested">Interested in joining</option> 
    <option value="job">Job enquiry</option> 
    <option value="other">Other</option> 
    <option value="question">Question about membership</option> 
</select></p> 
<p><label for="conSubject">Subject:<span class="required">*</span></label><input name="conSubject" id="conSubject" type="text" class="input"/></p> 
<p>Message:<span class="required">*</span> 
<textarea name="conMessage" cols="40" rows="5" class="textarea" id="conMessage"></textarea></p> 
<div class="buttonHolder"> 
<input class="text" type="submit" name="submitBtn" value="Submit" /> 
</div> 
</form> 
<?php } ?> 

隨着我mailer.php具有sendMail功能的文件如下:

function sendMail($conName,$conEmail,$conPhone,$conNatureof,$conSubject,$conMessage) 
{ 

//String to hold the error messages 
$errorText = ''; 

//START VALIDATION OF USER INPUT 

//Validating name 
if($conName == "") 
{ 
    $errorText = $errorText . "- Please enter a name<br />"; 
} 



//Validating email address 
//Must be a valid email address and is compulsory 
if($conEmail == "") 
{ 
    $errorText = $errorText . "- Please enter an email address<br />"; 
} 
elseif (!filter_var($conEmail, FILTER_VALIDATE_EMAIL)) 
{ 
    $errorText = $errorText . "- Email address was invalid<br />"; 
} 


//Validating enquiry type 
if($conNatureof == "-") 
{ 
    $errorText = $errorText . "- Please select your nature of enquiry<br />"; 
} 

//Validating subject and message 
if($conSubject == "") 
{ 
    $errorText = $errorText . "- Please enter a subject<br />"; 
} 

if($conMessage == "") 
{ 
    $errorText = $errorText . "- Please enter a message<br />"; 
} 


// If everything is OK, send the email 
if ($errorText == '') 
{ 
    $to = "[email protected]"; 
    $subject = $conSubject; 
    $message = $conMessage; 
    $from = $conEmail; 
    $headers = "From:" . $conName; 
    mail($to,$subject,$message,$headers); 
} 

return $errorText; 
} 

我知道大部分代碼是不必要的來診斷這個問題,儘管我認爲儘可能地給出這個問題是適當的。

所有幫助是極大的讚賞, 感謝

+3

請描述什麼是錯的,你得到了什麼錯誤?是錯誤報告? – Garytje

+1

好吧,讓我看到大量的代碼,但不知道是什麼問題 – Anigel

+0

對不起,夥計們,我的壞。不,我沒有打開error_reporting。 基本上,沒有電子郵件到我的電子郵件地址,我不知道爲什麼。對PHP很新穎,以前從未使用郵件功能。 – Fizzix

回答

1

你正在開發與驗證的接觸形式。請按照你會得到別人的想法的鏈接谷歌它contact form with validation

其他 google一下try in google

+0

伴侶,這太棒了。正是我需要的。您的幫助非常感謝:) – Fizzix

+0

它的確定,得到騎在php。這是夢幻般的 – hserusv