Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1013317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:04:57+00:00 2026-05-16T10:04:57+00:00

In my homepage I defined a form which uses the following script to send

  • 0

In my homepage I defined a form which uses the following script to send a mail:

<?php

/* Geben Sie hier Ihre E-Mail Adresse zwischen den beiden " an: */

$_emails[0] = "bla@bla.com";

// Wenn keine $_POST Daten übermittelt wurden, dann abbrechen
if(!isset($_POST) OR empty($_POST))
{
   header("Content-type: text/plain; charset=utf-8");
    echo "Es wurden keine Daten übermittelt!";
    exit;
}
else
{
    // Datum, Uhrzeit und Pfad zum eigenen Script feststellen
    $date = date("d.m.Y");
    $time = date("H:i");
    $host = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];

    // Empfänger feststellen und auf Gültigkeit prüfen
    if(isset($_POST['recipient']) AND isset($_emails[ $_POST['recipient'] ])
       AND preg_match("/^.*@.*\..*$/", $_emails[ $_POST['recipient'] ]))
    {
        $recipient = $_emails[ $_POST['recipient'] ];
    }
    // Wurde kein (gültiger) Empfänger angegeben, es mit $_email[0] versuchen
    elseif(isset($_emails[0]) AND preg_match("/^.*@.*\..*$/", $_emails[0]))
    {
        $recipient = $_emails[0];
    }
    // Ist auch diese Adresse ungültig, mit Fehlermeldung abbrechen
    else
    {
        header("Content-type: text/plain");
        echo "Fehler im Script - es wurde kein Empfänger oder eine ungültige E-Mail Adresse in \ angegeben.";
        exit;
    }

    // Wenn Betreff übermittelt, diesen verwenden
    if(isset($_POST['subject']))
    {
        $subject = $_POST['subject'];
    }
    // sonst einen Default Betreff verwenden
    else
    {
        $subject = "Formular Daten von {$_SERVER['HTTP_HOST']}";
    }

    // E-Mai Kopf generieren
    $email = "Formular Eintrag\n"
           . "\n"
           . "Am $date um $time Uhr hast das Script auf $host Formulardaten empfangen,\n"
           . "welche nach Angabe des Browsers von {$_SERVER['HTTP_REFERER']} stammen.\n"
           . "\n"
           . "Der Formular Inhalt wird nachfolgend wiedergegeben.\n"
           . "\n";

    // Alle $_POST Werte an den E-Mail Kopf anhängen
    foreach($_POST as $key => $value)
    {
        if($key == "redirect" OR $key == "recipient" OR $key == "subject")
        {
            continue;
        }
        $email .= "Fomular Feld '$key':\n"
               .  "=============================\n"
               .  "$value\n"
               .  "\n";
    }

    // E-Mail Fuß anfügen
    $email .= "=============================\n"
           .  "Ende der automatisch generierten E-Mail.";

    // Versuchen E-Mail zu versenden
    if(!mail($recipient, $subject, $email)) {
        // Ist dies gescheitert, Fehlermeldung ausgeben
        echo "Es ist ein Fehler beim Versenden der E-Mail aufgetreten,"
             . " eventuell liegt ein Konfigurationsfehler am Server vor.\n\n";
        exit;
    }

    // Wenn gewünscht, auf Bestätigungsseite weiterleiten
    if(isset($_POST['redirect']) AND preg_match("=^(http|ftp)://.*\..*$=", $_POST['redirect'])) {
       header("Location: ".$_POST['redirect']);
        exit;
    } else {
        header("Content-type: text/html");
        echo "Die E-Mail wurde erfolgreich versendet.";
    echo '<br>';
      echo '<a href="http://www.ornitholog.li/cms/index.php?page=kontakt">Zurueck</a>';
        exit;
    }
}

?>

It works ok, but however, the confirmation that the email was sent is displayed in a new window. I would prefer that the confirmation is displayed instead of the email form. How can I achieve that?

==EDIT===
I added the form:

<form action="./mail.php" method="post"> 
<table border="0">
<tbody>
<tr>
<td><label for="absender">Ihr Name:</label></td>
<td><input id="absender" name="absender" size="25" type="text" /></td>
</tr>
<tr>
<td><label for="email">Ihre E-Mail Adresse:</label></td>
<td><input id="email" name="email" size="25" type="text" /></td>
</tr>
<tr>
<td><label for="betreff">Betreff ihrer Nachricht:</label></td>
<td><input id="betreff" name="betreff" size="25" type="betreff" /></td>
</tr>
<tr>
<td><label for="nachricht">Ihre Nachricht:</label></td>
<td><textarea id="nachricht" cols="30" rows="8" name="nachricht"></textarea></td>
</tr>
<tr height="20">
<td></td>
<td></td>
</tr>
<tr>
<th colspan="2" align="center"><input name="abschicken" type="submit" value="Nachricht verschicken" /></th>
</tr>
</tbody>
</table>
</form>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:04:57+00:00Added an answer on May 16, 2026 at 10:04 am

    You change the action in your <form> to the same script as the form itself is in and check for the $_POST – if it is filled with something from the form, try to submit it.

    Basically, you just put the PHP-code above or below or around your HTML-form. Then I personally add a hidden field like <input type="hidden" name="sent" value="true"> which I can check for in PHP.

    if (!empty($_POST['sent']))
    {
        // Your PHP-Code for sending the mail
    }
    else
    {
        // Your HTML form
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wondering how I can break up my index.php homepage to multiple php
In urls.py, I defined as, url(r'^'+settings.URL_PREFIX+r'$', 'myapp.project.views.index', name=homepage), in settings.py, I defined URL_PREFIX as,
My homepage (or welcome page) will consist of data from two models (lets call
On my homepage I got: <ul id=login> <li> <a id=loginswitch href=./login-page>log-in</a> | </li> <li>
I just set up my new homepage at http://ritter.vg . I'm using jQuery, but
I have read the GOLD Homepage ( http://www.devincook.com/goldparser/ ) docs, FAQ and Wikipedia to
I'm trying to design a homepage for an MVC site that has two different
How do I create subdomains in ASP.NET? I have few links on my homepage(Home.aspx)
My clients home page is https://www.quakereadykit.com/store/home.php This was given to me by a previous
I'm writing a multiple user log in system using PHP and MySql, the way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.