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 怎么让数码管亮的同时让led执行流水灯代码
  • ¥20 SAP HANA SQL Script 。如何判断字段值包含某个字符串
  • ¥85 cmd批处理参数如果含有双引号,该如何传入?
  • ¥15 fx2n系列plc的自控成型机模拟
  • ¥15 时间序列LSTM模型归回预测代码问题
  • ¥50 使用CUDA如何高效的做并行化处理,是否可以多个分段同时进行匹配计算处理?目前数据传输速度有些慢,如何提高速度,使用gdrcopy是否可行?请给出具体意见。
  • ¥15 基于STM32,电机驱动模块为L298N,四路运放电磁传感器,三轮智能小车电磁组电磁循迹(两个电机,一个万向轮),如何通过环岛的原理及完整代码
  • ¥20 机器学习或深度学习问题?困扰了我一个世纪,晚来天欲雪,能饮一杯无?
  • ¥15 c语言数据结构高铁订票系统
  • ¥15 关于wkernell.PDB加载的问题,如何解决?(语言-c#|开发工具-vscode)