PHP邮件脚本和表单

时间:2016-01-24 09:03:26

标签: php

我一直在网站上使用以下脚本,但这次无法使​​用。

现在已弃用或我编辑错了吗?

这是标题......

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

$to = "phil@phillipvale.com.au"; //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>

感谢您的帮助,

菲尔:)

1 个答案:

答案 0 :(得分:0)

在我看来,使用$_REQUEST["firstname"] ["lastname"]的符号是错误的,可能会导致问题。当您尝试调试脚本时,请确保启用了error_reporting。

<?php

    error_reporting( E_ALL );

    if( isset( $_REQUEST['email'],$_REQUEST["firstname"],$_REQUEST["lastname"],$_REQUEST["phone"],$_REQUEST["email"] ) ){
        $to = "phil@phillipvale.com.au";
        $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';

?>