如何让我的联系表格发送给我电子邮件 [英] How to make my contact form send me Email

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

问题描述

这里是我的更新代码,试图让我的表单向我发送电子邮件。我在表单中添加了服务器PHP请求,但代码似乎没有读取它们。推动测试后,我的代码在网站上显示为文本。我记得有一次,我把PHP称为远离表单标记但不记得那个语法。

Here's my updated code trying to get my form to send me the email. I added the server php requests around the form, though the code doesn't seem to be reading them. My code is being displayed as text on the site after pushing for the test. I remember once, I called the php in the head away from the form markup but can't remember that syntax.

下面是我尝试使用的代码:

Here's the code I'm trying to use:

<?php 
if ($_POST["email"]<>'') { 
    $ToEmail = 'chaseoutt@gmail.com'; 
    $EmailSubject = 'Site contact form '; 
    $mailheader = "From: ".$_POST["email"]."\r\n"; 
    $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
    $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
    $MESSAGE_BODY = "Name: ".$_POST["name"]."<br>"; 
    $MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>"; 
    $MESSAGE_BODY .= "URL: ".$_POST["url"]."<br>"; 
    $MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."<br>"; 
    mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 
?> 
Your message was sent
<?php 
} else { 
?> 

  <p style="font-style:italic; font-size:12px; font-weigh: normal; margin-top: -89px;     margin-left: 33px;">Contact me written in a different language.</p> <img src="http://www.cameroncashwell.com/imgs/pointing-left.png" style="float: right; margin-right: 140px; margin-top: -89px;">

<div class="form-div"> 
    <form id="fvujq-form1" style="font-size:22px; color:#333;" method="post" action="">
      <div class="form-row"><span class="label">Name *</span><input type="text" name="name" /></div>
      <div class="form-row"><span class="label">Email *</span><input type="text" name="email" /></div>
      <div class="form-row"><span class="label">URL</span><input type="text" name="url" /></div>
      <div class="form-row"><span class="label">Comment *</span><textarea name="comment"></textarea></div>
      <div class="form-row"><input class="submit" type="submit" value="Submit"></div>
    </form>
</div>
    <?php 
}; 
?>

Wheres my error?

Wheres my error?

推荐答案

电子邮件不是通过客户端的JavaScript代码发送的;它是从服务器发送的。当用户点击提交,并且所有客户端验证都已通过时,表单数据会POST到服务器。表单元素的action属性指定服务器上的哪个URL应该接收POST的表单数据;即类似于action =send_email.php或类似的东西。

Email is not sent by JavaScript code in the client; it is sent from the server. When the user hits submit, and all the client side validations have passed, the form data is POST'ed to the server. The form element's "action" attribute specifies what URL on the server should receive the POST'ed form data; i.e. something like action="send_email.php" or something like that.

电子邮件如何在服务器上实际生成,完全取决于所使用的服务器技术,例如PHP或JSP,或其他。

How the email is actually generated, on the server is entirely dependent on the server technology in use, e.g. PHP, or JSP, or whatever.

因此,您的代码中缺少两件事:

So two things are missing in your code above:


  1. action =在表单中,以及
  2. 接收数据并实际发送电子邮件的服务器端代码(PHP文件或其他)(对应于#1)
  3. >

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

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