0

我只需要一个非常基本/简单的表格来发送电子邮件,但它似乎不起作用,我不知道为什么?我知道代码不是很先进,可能看起来很“丑陋”,但它可以满足我的“需要”

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

    $full_name = $_POST['fullName'];
    $phone = $_POST['phoneNumber'];
    $adMessage = $_POST['emailMessage'];

    //send email
    $to = "info@lalalalala.co.uk";
    $from = $_POST['emailAddress'];
    $subject = $_POST['emailSubject'];

    $message = "Full name: " . $full_name . "\n";
    $message .= "Phone number: " . $phone . "\n";
    $message .= "Email Address: " . $from . "\n";
    $message .= "Additional Message: " . $adMessage;


    $headers = "From:" . $full_name;
    mail($to, $subject, $message, $headers);
}

HTML

<form action='' method='post'>

    <fieldset><label id="fullName">Full Name</label>
    <input type="text" name="fullName" value="Please Enter Your Full Name" onclick="this.value=''"  /></fieldset>

    <fieldset><label id="emailAddress">Email Address</label>
    <input type="text" name="emailAddress" value="Please Enter Your Email Address" onclick="this.value=''"  /></fieldset>

    <fieldset><label id="phoneNumber">Phone Number</label>
    <input type="text" name="phoneNumber" value="Please Enter Your Phone Number" onclick="this.value=''"  /></fieldset>

    <fieldset><label id="emailSubject">Email Subject</label>
    <input type="text" name="emailSubject" value="Please Enter Email Subject" onclick="this.value=''"  /></fieldset>

    <fieldset><label id="emailMessage">Your Message</label>
    <textarea cols="10" rows="20" name="emailMessage" onclick="this.value=''" >Please Enter Your Message</textarea></fieldset>

    <fieldset><input type="image" src="images/submit.png" id="submit" onclick="show_alert();" /></fieldset>
</form>

谢谢 :)

4

3 回答 3

0

改变

if (isset($_POST['email']))

if($_SERVER['REQUEST_METHOD'] == 'POST')

您的表单没有名为的元素email- 因此它永远不会进入该if块。替换检查请求方法是否POST为已发布的表单。

于 2012-07-26T12:36:47.300 回答
0

您尚未设置任何名为email. 您的第一个条件不会被评估为真,因此您跳过后面的所有内容。

于 2012-07-26T12:36:55.980 回答
0

我看不到您在您的情况下使用的input field名为电子邮件的表格中的任何内容,即

if (isset($_POST['email'])){....}

有一个名为emailAddress的字段,因此请使用:

if (isset($_POST['emailAddress'])){....}

希望这可以帮助。

于 2012-07-26T12:37:11.580 回答