H1 Element

the mail() function

Moderators: egami, macek, gesf

Post Reply
vict861a
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Nov 19, 2020 7:36 am

Thu Nov 19, 2020 7:38 am

Hello I am trying to get a H1 element into a variable in my PHP my code here is my code:

Code: Select all

<main>
      <form class="contact-form" action="contactform.php" method="post" enctype="multipart/form-data">
          <h1 name="product-name">1x1Logo</h1>
        <div class="txtb">
          <label>Vollständiger Name</label>
          <input type="text" name="name" value="" placeholder="Vollständiger Name">
        </div>

        <div class="txtb">
          <label>Farbe</label>
          <input type="text" name="color" value="" placeholder="Wählen Sie eine Farbe.">
        </div>

        <div class="txtb">
          <label>E-Mail</label>
          <input type="text" name="mail" value="" placeholder="Ihre E-Mail">
        </div>

        <div class="txtb">
          <label>Telefonnummer</label>
          <input type="text" name="phone" value="" placeholder="Ihre Telefonnummer(nicht notwendig)">
        </div>
          <input type="file" name="attachment">
        <div class="txtb">
          <label>Botschaft</label>
          <textarea name="message" placeholder="Schreiben..."></textarea>
        </div>
        <div class="submit-btn">
          <button type="submit" name="submit">Senden</button>
        </div>
        <div class="help-btn">
          <a type="submit" name="help">Um Rat fragen</a>
        </div>
      </form>
    </main>

Code: Select all

<?php

if (isset($_POST['submit'])) {
  $product = $_POST['product-name'];
  $name = $_POST['name'];
  $color = $_POST['color'];
  $mailFrom = $_POST['mail'];
  $phone = $_POST['phone'];
  $message = $_POST['message'];

  $mailTo = "test@victorogsigrid.dk";
  $headers = "From: ".$mailFrom;
  $txt = "You have received an e-mail from ".$name.".\n\n"."Product: ".$product.".\n\n"."Color: ".$color.".\n\n"."Mail/Phone: ".$mailFrom."/".$phone.".\n\n"."User Wrote: ".$message;

  mail($mailTo, $product, $txt, $headers);
  header("Location: ../index.php?mailsend");
  echo('Mail has been send!');
}

?>
Any help?
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 1190
Joined: Mon Feb 22, 2016 5:52 pm

Thu Nov 19, 2020 12:39 pm

What is your problem? Explain clearly what you expect to happen and what actually happens.

Your PHP code has problems.
vict861a
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Nov 19, 2020 7:36 am

Fri Nov 20, 2020 2:28 pm

I want to get my H1 element into the product_name variable in my PHP code (sorry for the late answer)
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 1190
Joined: Mon Feb 22, 2016 5:52 pm

Sat Nov 21, 2020 5:27 am

You don't have a "product_name" variable?

Your problem has not been explained clearly, without knowing what you expect and what you are struggling with, I cannot help you.

Do you know how to set a variable?
vict861a
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Nov 19, 2020 7:36 am

Sat Nov 21, 2020 6:08 am

Okay fine the variable is called $product
User avatar
Strider64
php-forum GURU
php-forum GURU
Posts: 396
Joined: Sat Mar 23, 2013 8:24 am
Location: Livonia, MI
Contact:

Sun Nov 22, 2020 5:55 am

First of all you can't use h1 element tag you need to use an input of some sort:

for example:

Code: Select all

<input class="image-upload" type="file" name="file">
where you can call name="file" this name="product" if you want, but I normally don't do that.

You don't have to do it this you can use a selection element which I think you are more after, but first things first. That is to get the code to work correctly. Then you would do something line the follow (that is if you want to process the image itself) :

Code: Select all

$product = $_FILES['file']['tmp_name'];
then process of that file can occur.

However, I think you are more after something like the following:

Code: Select all

<select name="product" id="product">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>
If you want to "display" the image of the product then I would recommend using radio or check boxes instead.
Life is a fig newton of your imagination! https://www.miniaturephotographer.com
Post Reply