2016-01-24 93 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'; 

?>