2009-08-14 6 views
0

코드 또는 더 나은 방법으로 수정하는 데 문제가있는 사람이 있습니까? 어떤 이유로 내 연락처 양식에 제출하면 "error.html"페이지가 표시되지만 내 계정으로 이메일이 전송됩니다.PHP 전자 메일 양식

$EmailTo = "[email protected]"; 
$Subject = "Contact Submission"; 

$Name = Trim(stripslashes($_POST['name'])); 
$Email = Trim(stripslashes($_POST['email'])); 
$Budget = Trim(stripslashes($_POST['budget'])); 
$Message = Trim(stripslashes($_POST['message'])); 

// prepare email body text 
$Body = 'Contact Submission'."\n"; 
$Body .= 'Name:  ' .$Name."\n"; 
$Body .= 'Email:  ' .$Email."\n"; 
$Body .= 'Budget:  ' .$Budget."\n"; 
$Body .= 'Message:  ' .$Message."\n"; 


// send email 
$success_email = mail($EmailTo, $Subject, $Body, "From: <$Email>"); 

// redirect to success page 
// CHANGE THE URL BELOW TO YOUR "THANK YOU" PAGE 
    if ($success){ 
    header ('location:thankyou.html'); 
    } 
    else{ 
    header ('location:error.html'); 
    } 
+1

출구를 배치하는 것이 좋습니다. 귀하의 위치 헤더 아래 - 페이지가 예상치 못한 이벤트에서 구문 분석되지 않도록합니다. – alex

답변

8

변경

if ($success){ 

성공이 존재하지 않는 $ ...

if ($success_email){ 

0
$EmailTo = "[email protected]"; 
$Subject = "Contact Submission"; 

$Name = Trim(stripslashes($_POST['name'])); 
$Email = Trim(stripslashes($_POST['email'])); 
$Budget = Trim(stripslashes($_POST['budget'])); 
$Message = Trim(stripslashes($_POST['message'])); 

// prepare email body text 
$Body = 'Contact Submission'."\n"; 
$Body .= 'Name:   ' .$Name."\n"; 
$Body .= 'Email:   ' .$Email."\n"; 
$Body .= 'Budget:   ' .$Budget."\n"; 
$Body .= 'Message:  ' .$Message."\n"; 


// send email 
$success_email = mail($EmailTo, $Subject, $Body, "From: <$Email>"); 

// redirect to success page 
// CHANGE THE URL BELOW TO YOUR "THANK YOU" PAGE 
    if ($success_email){ 
    header ('location:thankyou.html'); 
    } 
    else{ 
    header ('location:error.html'); 
    } 
0
//Checking for empty for redirecting error page 
if(empty($Name) || empty($Email)||empty($Budget)) 
{ 
    header('Location:error.html'); 
    exit; 
} 

//Send the email! if the fileds are not empty 
mail($EmailTo, $Subject,$Body,"From: <$Email>"); 

//One the email is sent, Redirect to thankyou page. 
header('Location: thankyou.html'); 
관련 문제