如何让我的表单实际发送电子邮件? [英] How do I get my form to actually send an email?

查看:127
本文介绍了如何让我的表单实际发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在为我的投资组合制作联系表格。我对php很新,所以我不太了解。但是,我发现一个网站似乎很容易使用。我已将其包含在此处:您网站的简单PHP联系表单脚本 [ ^ ]



我根据自己的喜好稍微修改了HTML5表单,但它工作正常,但我无法通过它来验证表单。长话短说,我去看了我真棒的教授,以获得一些帮助,验证确实有效。他告诉我,PHP中的一些脚本是不必要的,所以我们删除了他认为不必要的内容。问题在于:当我测试表单时,它会显示Email Sent!但我实际上从未收到过电子邮件。在我和我的教授改变之前,它确实发了电子邮件。我浏览了php,即使在与我的教授进行更改后,一切似乎都是正确的。此外,它不再检查验证,但是当我和我的教授一起检查它时,它正在工作。我真的很感激任何帮助。





这就是我现在所拥有的:



 <  表格   < span class =code-attribute>   action   =  contact.php    method   =  POST    enctype   =  multipart / form-data >  
< 输入 类型 = hidden name = action value < span class =code-keyword> = 提交 >
< div class = col-md-6 >
< label > < input 名称 < span class =code-keyword> = name 类型 = text id = name 验证 value = 占位符 = 您的姓名* / > < / label >
< label > < 输入 名称 = 电子邮件 类型 = text id = email 验证 value = 占位符 = 您的电子邮件* / > < / label >
< / div >

< div class = col-md-6 >
< label > < 正文区域 名称 = 消息 验证 占位符 = 您的留言* > < / textarea > < / label >
< / div >
< 输入 type = 提交 value = 发送 / >
< / form >
<? php

$ name = $ _ POST [< span class =code-string>' name'];
$ email = $ _ POST [' email'];
$ message = $ _ POST [' message'];
if (($ name == )||($ email == )||($ message = = ))
{
echo 所有字段都是必填项,请填写< a href = \\ >形式< / a>再次。;
}
else {
$ from = From:$ name< $ email> ; \ r\\\
Return-path:$ email
;
$ subject = 使用您的联系表格发送的消息;
mail( myemail@gmail.com,$ subject,$ message,$ from );
echo 发送电子邮件!;
}

?>





我尝试了什么:



我已经尝试回到原来的代码,如下所示(没有行和列东西):



https://www.123contactform.com/simple-php-contact-form.html

解决方案

name =


_POST [' name'];

电子邮件=

I've been working on a contact form for my portfolio. I'm fairly new to php so I don't know much. However, I found a website online that seems fairly easy to use. I've included it here: Simple PHP contact form Script for your website[^]

I altered the HTML5 form a little bit to suit it to my liking and it was working fine but I could not get it to validate the form. Long story short, I went to see my awesome professor for some help on that and the validation actually worked. He informed me that some of the script in the PHP was unnecessary so we removed what he thought was unnecessary. Here's the issue: when I test out the form it says "Email Sent!" but I never actually get an email. It did send emails before I altered it with my professor. I went over the php and everything seems to be correct even after making the changes with my professor. Also it doesn't check for validation anymore but it was working when I went over it with my professor. I would really appreciate any help.


Here's what I have now:

<form  action="contact.php" method="POST" enctype="multipart/form-data">
                                <input type="hidden" name="action" value="submit">
                                <div class="col-md-6">
                                <label><input name="name" type="text" id="name" validate value="" placeholder="Your Name *"/></label>
                                <label><input name="email" type="text" id="email" validate value="" placeholder="Your Email *"/></label>
                                </div>
                               
                                <div class="col-md-6">
                                <label><textarea name="message" validate placeholder="Your Message *" ></textarea></label>
                                </div>
                               <input type="submit" value="Send"/>
                              </form>
                               <?php
	
									$name=$_POST['name'];
									$email=$_POST['email'];
									$message=$_POST['message'];
									if (($name=="")||($email=="")||($message==""))
										{
										echo "All fields are required, please fill <a href=\"\">the form</a> again.";
										}
									else{        
										$from="From: $name<$email>\r\nReturn-path: $email";
										$subject="Message sent using your contact form";
										mail("myemail@gmail.com", $subject, $message, $from);
										echo "Email sent!";
										}
									 
								?>



What I have tried:

I've tried going back to the original code as seen here(without the row and column stuff):

https://www.123contactform.com/simple-php-contact-form.html

解决方案

name=


_POST['name'];


email=


这篇关于如何让我的表单实际发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆