doutuan4361 2017-09-18 13:55
浏览 61
已采纳

从html代码发送php邮件[重复]

This question already has an answer here:

after I tried to get an answer to my question here, I try it with a new thread.

Little explanation: I have a Contact-Form with 180 input fields + calculation for every field. I want to send all the fields + the calculated value with e-mail.

Thats just an example of one of the 180 rows which i need to send with mail:

<form id="wohnzimmer" method="post" action="mailto:myemail@mymail.com">
  <div style="clear: left;">
    <div class="text">
      DIV TEXT - ANY ARTICLE
    </div>    
    <div class="restText"> 
      <input id="w0" type="text" class="raumeinheitInput_x4 inputWidth" value="0" name="ARTICLENAME" /> = <span class="raumeinheitenErgebnis" id="w0g"> CALCULATED NUMBER </span>
    </div>
  </div>

// 179 more input-fields will follow here!!

<input type="submit" value="Send Email" />

My Calculation is working, so i just need help to send all my content via mail.

My question is: How can i send the mail without Outlook or Thunderbird (i think i need php) with the following Content:

Name of the article , the Number from the Input field (w0) + the calculated number (w0g)?

I hope anyone has an answer for me. Thanks in advance.

</div>
  • 写回答

2条回答 默认 最新

  • dongzouqie4220 2017-09-18 14:03
    关注

    You need to create a PHP file to handle these "server-side" actions for you. Then set the action attribute of your HTML form to this PHP page. When the HTML is submitted, the 180 input fields are then all POSTed to the PHP page inside a variable called $_POST. You can then work on that data to create the string you want and finally use the mail() function (or perhaps a pre-built emailer package that gives you a bit more control) to actually send that email.

    Your new HTML

    <form id="wohnzimmer" method="post" action="send_email.php">
    

    Note:

    You say you want to get the name of the article, w0 and w0g, but you have only put w0 inside an input. Only inputs, textareas and selects will be sent to the PHP script. You will need to change your HTML to make sure they are all gathered. I'd suggest using array syntax to do this:

    <input type="hidden" name="article0" value="ARTICLENAME" />
    <input id="w0" type="text" class="raumeinheitInput_x4 inputWidth" value="0" name="w0" /> = <input type="text" class="raumeinheitenErgebnis" name="w0g" id="w0g"> CALCULATED NUMBER </input>
    
    <input type="hidden" name="article1" value="ARTICLENAME" />
    <input id="w1" type="text" class="raumeinheitInput_x4 inputWidth" value="0" name="w1" /> = <input type="text" class="raumeinheitenErgebnis" name="w1g" id="w1g"> CALCULATED NUMBER </input>
    

    I'm making some presumptions here about your data but that should make sense. You may want to write a PHP loop to output the data if you can. Also it might help you to use HTML input arrays to simplify things a bit.

    The PHP

    You'd end up with something like this very rough example:

    <?php
    $myString = "";
    for ($x=0;$x<180;$x++) {
        $tempString = $_POST['article' . $x] . $_POST['w' . $x] . $_POST['w' . $x . 'g'];
        // don't forget to sanitize this data!!
        $myString .= sanitize_however_you_want($tempString);
    }
    
    // now email
    mail('myemail@mymail.com', 'Email Subject', $myString, 'From: you@yoursite.com' '-fyou@yoursite.com');
    
    1. Read more about posting forms here: Dealing with forms
    2. Read more about sending email here: The mail() function
    3. Read more about HTML input arrays in this stack question
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题