2016-01-24 121 views
0

我一直在網站上使用下面的腳本,這次不能使用它。PHP郵件腳本和表格

現在是否被棄用或我編輯過錯?

這是標題...

if (isset($_REQUEST['email'])) 
{ 

$to = "[email protected]"; //insert correct email here 
$subject = "California Tacos - Franchise Opportunities - Contact Form"; 
$message = "Name: " . $_REQUEST["firstname"] ["lastname"] . "\n" . "Phone: " . $_REQUEST["phone"] . "\n" . "Email: " . $_REQUEST["email"] . "\n" ."State: " . $_REQUEST["state"] . "\n" . "Comments: " . $_REQUEST["comments"]; 
$from = $_REQUEST['email']; 
$headers = "From: $from"; 
mail($to,$subject,$message,$headers); 
$strError = false; 
} 
else 
{ 
$strError = true; 
} 

這是形式本身...

<form method="post" action="" id="myForm"> 

<?php 

if ($strError != false) 
{ 

?> 

<label for="name">FIRST NAME</label> 
<input name="firstname" type="text" required id="firstname" placeholder="Please enter your first name"/> 

<label for="name">LAST NAME</label> 
<input name="lastname" type="text" required id="lastname" placeholder="Please enter your last name"/> 

<label for="email">EMAIL</label> 
<input name="email" type="text" required id="email" placeholder="Please enter your email"/> 

<label for="phone">PHONE</label> 
<input name="phone" type="text" required id="phone" placeholder="Please enter your phone number"/> 

<label for="state">WHERE DO YOU LIVE?</label> 
<select name="state" id="state"> 
    <option value="" disabled selected>Please select where you live</option> 
    <option value="New South Wales">New South Wales</option> 
    <option value="Queensland">Queensland</option> 
    <option value="South Australia">South Australia</option> 
    <option value="Tasmania">Tasmania</option> 
    <option value="Victoria">Victoria</option> 
    <option value="Western Australia">Western Australia</option> 
</select> 

<label for="comments">COMMENTS</label> 
<textarea name="comments" required id="comments"></textarea> 

<p><input name="submit" type="submit" value="SUBMIT"/></p> 

<?php 

} 
else 
{ 
?> 

Thank you, We will be in touch shortly.       

<? 
} 
?> 
</form> 

感謝您的幫助,

Phil :)

+1

'$ _REQUEST [「名字」] [「姓氏」]'可疑,我 – RamRaider

+0

嘗試一個'if'聲明爲您'郵件()'函數,看看您的郵件腳本返回TRUE;和那麼電子郵件不會傳送,或者它只是返回'false'? – prakashchhetri

回答

0

我的眼睛使用的符號$_REQUEST["firstname"] ["lastname"]是錯誤的,並可能導致問題。確保在嘗試調試腳本時確保error_reporting處於打開狀態。

<?php 

    error_reporting(E_ALL); 

    if(isset($_REQUEST['email'],$_REQUEST["firstname"],$_REQUEST["lastname"],$_REQUEST["phone"],$_REQUEST["email"])){ 
     $to = "[email protected]"; 
     $subject = "California Tacos - Franchise Opportunities - Contact Form"; 
     $message = "Name: " . $_REQUEST["firstname"].' '.$_REQUEST["lastname"] . "\n" . "Phone: " . $_REQUEST["phone"] . "\n" . "Email: " . $_REQUEST["email"] . "\n" ."State: " . $_REQUEST["state"] . "\n" . "Comments: " . $_REQUEST["comments"]; 
     $headers = "From: {$_REQUEST['email']}"; 

     $result=mail($to, $subject, $message, $headers); 
    } 
    echo $result ? 'Success' : 'Failed'; 

?>