我有一个有180个输入字段+每个字段的计算的联系人表格.我想用电子邮件发送所有字段+计算值.
这只是我需要用邮件发送的180行中的一个例子:
<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" />
我的计算是可行的,所以我只需要帮助通过邮件发送我的所有内容。
我的问题是:如何在没有Outlook或Thunderbird(我想我需要php)的情况下发送邮件,内容如下:
项目名称,输入字段中的编号。(W0)+计算数(W0g)?
发布于 2018-08-13 12:53:18
你需要创建一个PHP文件来处理这些“服务器端” 。然后设置action
属性将HTML表单添加到此PHP页面。当HTML提交时,180个输入字段将全部POST
到PHP页面的一个变量名为$_POST
。然后,你可以使用该数据来创建所需的字符串,并最终使用mail()
功能(或者可能是一个预先构建的电子邮件包,它给你提供了更多的控制)来实际发送电子邮件。
<form id="wohnzimmer" method="post" action="send_email.php">
注:
你说你想知道这篇文章的名字,w0
和w0g
,但你只把w0
在输入里面。只input
S,textarea
S和select
S将被发送到PHP脚本。你需要更改HTML以确保它们都被收集起来。我建议使用数组语法来这样做:
<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>
我在这里对你的数据做了一些假设,但这应该是有意义的。如果可能的话,你可能希望编写一个PHP循环来输出数据。此外,它还可以帮助你使用HTML输入数组来稍微简化一些事情。
你最终会有这样的结果 :
<?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');
发布于 2018-08-13 14:04:44
你可以使用 :
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load composer's autoloader
require 'vendor/autoload.php';
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user@example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen@example.com'); // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');
//Attachments
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
https://stackoverflow.com/questions/-100002096
复制相似问题