1

所以我能够让用户一直到感谢页面,但是当我检查我的电子邮件(在真实代码中是正确的)时,我什么都没有。任何帮助,将不胜感激。

<?php
$myemail = "myEmailInAString@gmail.com";

$name = check_input($_POST['full_name'], "Enter your name");
$phone = check_input($_POST['phone'], "Enter a phone number");
$email = check_input($_POST['email']);
$address = check_input($_POST['address'], "Enter your address");
$city = check_input($_POST['city'], "Enter your city");
$state = check_input($_POST['state'], "Enter your state");
$zip_code = check_input($_POST['zip_code'], "Enter your zip_code");
$asking_price = check_input($_POST['asking_price'], "Enter your asking_price");


if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)){
    show_error("E-mail address not valid");
}
$message = "
Name: $name
E-mail: $email
Phone Number: $phone
Address: $address
$city, $state, $zip_code
Asking Price: $asking_price";

mail($myemail, "$city Inquiry", $message);

header('Location: thanks.html');
exit();

function check_input($data, $problem=''){
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    if ($problem && strlen($data) == 0){
        show_error($problem);
    }
    return $data;
}

function show_error($myError){
    ?><html>
    <body>

    <p>Please correct the following error:</p>
    <strong><?php echo $myError; ?></strong>
    <p>Hit the back button and try again</p>

    </body>
    </html><?php
    exit();
}
?>

此外,任何关于 php 表单的提示将不胜感激。说到表格,我是个菜鸟……

4

1 回答 1

0

您忘记设置电子邮件标题

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: $name <$email>' . "\r\n";
$headers .= 'From: Your name <YOURE@EMAIL>' . "\r\n";

mail($to, $subject, $message, $headers);


如果您尝试从 localhost 发送电子邮件,则需要配置邮件服务器。

于 2013-11-05T05:38:26.547 回答