php表单发送不发送电子邮件(php form post not sending email)

编程入门 行业动态 更新时间:2024-10-27 08:35:24
php表单发送不发送电子邮件(php form post not sending email)

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

<?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表单的提示将不胜感激。 表格上我是一个完全的菜鸟...

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...

最满意答案

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

// 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发送电子邮件,则需要配置邮件服务器。

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.

更多推荐

本文发布于:2023-07-16 13:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1129054.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   发送电子邮件   php   form   email

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!