0

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.

Kjarudi
  • 15
  • 5
  • Try a Mail library like https://swiftmailer.symfony.com/ or https://docs.zendframework.com/zend-mail/intro/. These can be installed by Composer, and you don't need the full framework to use them! – delboy1978uk Sep 18 '17 at 14:01
  • 1
    There is a million of examples on sending emails in php and there is no difficulty to send values via php in email. you can send 180 or 1800 values it's your choice just embed the values in body message as you can see in below answers. – Shahroze Nawaz Sep 18 '17 at 14:06

2 Answers2

1

you 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;
}
colapiombo
  • 179
  • 1
  • 3
  • 13
1

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
LeonardChallis
  • 7,759
  • 6
  • 45
  • 76
  • Hi, thanks for your Help :) i try to give you a hint what it should look like. ARTICLENAME (not editable) COUNT OF ARTICLES (Input field multiplied by a given number) = CALCULATED NUMBER (not editable) Then i need to send an email with these three things for all 180 Articles. Here is the whole file if you need to take a look ^^ [link](http://nordsee-umzuege.de/wp-content/uploads/2017/08/Nordsee_Script.html) – Kjarudi Sep 18 '17 at 14:29
  • The Php looks very nice. But i think the Problem is, that i cant put the Text and the calculated number in that email? – Kjarudi Sep 18 '17 at 14:37
  • My answer covers this. You need to make sure ALL the data you want to email is sent to the PHP script. Meaning that data needs to be in inputs. – LeonardChallis Sep 18 '17 at 14:39