简体   繁体   English

php 中的 html 表格未从服务器发送到 email

[英]html form in php not sending to email from server

i have a form in my php page like the following:我的 php 页面中有一个表格,如下所示:

 <form action="" method="post"> <h1>Sign Up Now! <!-- <span>Sign up and tell us what you think of the site!</span> --></h1> <div class="inner-wrap"> <label>Your Full Name <input type="text" name="field1" /></label> <label>Address <textarea name="field2"></textarea></label> </div> <div class="button-section"> <input type="submit" value="Submit" name="Sign Up" /> </div> </form>

the code for it is below:它的代码如下:

 <?php if(isset($_POST['submit'])){ $to = "zubairking@gmail.com"; // this is your Email address $from = $_POST['field1']; // this is the sender's Email address $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $subject = "Form submission"; $subject2 = "Copy of your form submission"; $message = $first_name. " ". $last_name. " wrote the following:". "\n\n". $_POST['message']; $message2 = "Here is a copy of your message ". $first_name. "\n\n". $_POST['message']; $headers = "From:". $from; $headers2 = "From:". $to; mail($to,$subject,$message,$headers); mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender echo "Mail Sent. Thank you ". $first_name. ", we will contact you shortly."; // You can also use header('Location: thank_you.php'); to redirect to another page. }?>

my server is also mail enabled, but this code of mine is not sending values to my mail, all the code is in one page, can anyone please tell me whats wrong with my code?我的服务器也启用了邮件,但是我的这段代码没有向我的邮件发送值,所有代码都在一页中,谁能告诉我我的代码有什么问题? thanks in advance提前致谢

You need the submit button to have name="submit" for the condition if(isset($_POST['submit'])) to be met.您需要提交按钮具有name="submit"才能满足条件if(isset($_POST['submit'])) You also need to add elements with names='first_name', 'last_name' and 'message' in the form to apply them in your email messages as you are trying to do.您还需要在表单中添加 names='first_name'、'last_name' 和 'message' 的元素,以便在您尝试执行的 email 消息中应用它们。 You also need your <input type="text" name="field1" /> to be an email instead a name, given that you are using it to set the sender of the email.您还需要您的<input type="text" name="field1" />成为 email 而不是名称,因为您使用它来设置 email 的发件人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM