简体   繁体   English

联系表格(具体选择)和电子邮件

[英]contact form (specifice slection) and email

I want to make a contact form and my problem is :我想制作一个联系表格,我的问题是:

  • by the option select the contact type (peter or Michael) , if i want to contact for example peter and press the submit button it the form goes to his email example peter@gmail.com and so on.... how to solve the problem inside (select option && contact_procees code) please advise me通过选项选择联系人类型(彼得或迈克尔),如果我想联系例如彼得并按下提交按钮,表单将转到他的电子邮件示例 peter@gmail.com 等等....如何解决里面的问题(选择选项&&contact_procees代码)请告诉我

 //// contact.php ///// <form class="contact-form" method="post" name="contact" id="f"> <table width="85%" border="0" cellspacing="0" cellpadding="0"> <td>Contact Person :</td> **strong text** <td><select id="agents"> <option value="1">Peter</option> <option value="2">Michael</option> </select> </td> </tr> <tr> <td valign="top">Text :</td> <td><textarea style="background-color:#f5f5f5; color:#000" name="msg" type="text" class="contact-textarea"></textarea></td> </tr> </table> <br /> <br /> <table width="60%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="150px"></td> <td align="left"> <input type="reset" class="submit" value="Reset" /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="submit" class="submit" value="Send" onclick="sendForm(); return false;" id="btn" /> </td> </tr> </table> </form> /// JAVA SCRIPT CODE SEND FOR <script type="text/javascript"> function sendForm() { document.getElementById('btn').value="....."; var oData = new FormData(document.forms.namedItem("contact")); var oReq = new XMLHttpRequest(); oReq.open("POST", "contact_proccess.php", true); oReq.onload = function(oEvent) { if (oReq.status == 200) { if(oReq.responseText=="1") alert("Thankyou, the message is sent ."); else alert("There was error in proccessing your request.Please try again later"); } else { alert("There was error in proccessing your request.Please try again later"); } document.getElementById("f").reset(); document.getElementById('btn').value="Send"; }; oReq.send(oData); } </script> //// contact_process.php <?php error_reporting(0); echo "1"; function error(){ exit("0"); } if(!isset($_POST['name']) or !isset($_POST['work']) or !isset($_POST['subject']) or !isset($_POST['msg'])){ error(); } $name=$_POST['name']; $work=$_POST['work']; $subject=$_POST['subject']; $msg=$_POST['msg']; if($name=="" or $work=="" or $subject=="" or $msg==""){ error(); } $message= <strong>Name</strong> : '.$_POST['name'].'<br> <strong>Work</strong> : '.$_POST['work'].'<br> <strong>contact</strong> : '.$_POST['subject'].'<br> <strong>Text</strong> : '.$_POST['msg'].'<br> </div>'; $headers = "MIME-Version: 1.0" . "\\r\\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\\r\\n"; // More headers $headers .= 'From:Mypage Website <webmaster@mypage.com>' . "\\r\\n"; $subject="Contact"; $to="peter@gamail.com"; /// what should i do for others mail($to,$subject,$message,$headers); ?>

You can put your email id in select value like您可以将您的电子邮件 ID 放在选择值中,例如

    <select id="agents" name="agents">
      <option value="peter@gmail.com">Peter</option>
      <option value="michael@gmail.com">Michael</option>
    </select>

Get it in php like在 php 中获取它

    $to = $$_POST['agents'];

and then send the email like you are sending然后像你发送的那样发送电子邮件

   mail($to,$subject,$message,$headers);

I hope answred the question.我希望回答这个问题。

I would POST the form to a page called "sendmail.php" and there pick up the selected value (peter/micheal).我会将表单发布到一个名为“sendmail.php”的页面,然后在那里获取选定的值(peter/micheal)。
You can name them 1 and 2 if you like.如果您愿意,可以将它们命名为 1 和 2。

The thing about having it javascript or in the html code is that the mail is in plain sight.使用 javascript 或 html 代码的事情是邮件是显而易见的。
There are robots crawling for mails and the mails printed in html are a likely victim.有机器人抓取邮件,以 html 打印的邮件很可能是受害者。

Once the send has been done you could echo out thank you and it worked, or did not work.发送完成后,您可以回显谢谢,它起作用了,或者不起作用。

But my advice is POST the values and send them in php, that way it's secure from crawlers但我的建议是 POST 值并在 php 中发送它们,这样它就可以免受爬虫的侵害

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

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