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>
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 POST
ed 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.
<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 input
s, textarea
s and select
s 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.
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');
mail()
functionyou can use a mail() (http://php.net/manual/en/function.mail.php ) but i think is better if you use a PHPMailer library (https://github.com/PHPMailer) is very simple
<?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;
}