php表单发送不发送电子邮件

时间:2022-10-23 19:14:26

So I was able to get the user all the way to the thank you page, but when I check my email (which is correct in the real code), I had nothing. any help would be appreciated.

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

<?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();
}
?>

also, any tips on php forms would be greatly appreciated. I am a total noob when it comes to forms...

此外,任何关于PHP表单的提示将不胜感激。表格上我是一个完全的菜鸟...

1 个解决方案

#1


0  

You have forget to set email headers

您忘记设置电子邮件标头了

// 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);


If you are trying to send emails from localhost, than you need to configure the mail server.

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

#1


0  

You have forget to set email headers

您忘记设置电子邮件标头了

// 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);


If you are trying to send emails from localhost, than you need to configure the mail server.

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