1. Startseite
  2. Portal
  3. Forum
    1. Unerledigte Themen
  4. Galerie
    1. Alben
    2. Karte
  5. Lexikon
  6. Kartensysteme
    1. Europaanalyse
    2. Gewitteranalyse
    3. Nowcast
  7. FAQ
  • Anmelden
  • Registrieren
  • Suche
Dieses Thema
  • Alles
  • Dieses Thema
  • Dieses Forum
  • Artikel
  • Forum
  • Galerie
  • Lexikon
  • Seiten
  • FAQ
  • Erweiterte Suche
  1. Forum
  2. Sonstiges
  3. PC-Ecke

Kurzmitteilung per php

  • Planetarier
  • 27. Juni 2016 um 19:30
  • Erledigt
  • Planetarier
    MOD Astronomie
    Reaktionen
    102
    Punkte
    47.732
    Beiträge
    6.652
    Bilder
    44
    • 27. Juni 2016 um 19:30
    • #1

    Hallo,

    Ich habe eine Seite, in dem dort ein Kurzkontakt eingebaut ist und dieser die Mail über eine php-Datei an meine Email-Adresse sendet.
    Leider werde ich aus dem Code in dieser Datei nicht schlau, wo ich meine Email Adresse einbauen soll.

    Hier der Code:


    PHP
    <?php
    
    
    /**
     * Define the from email
     */ 
    // email
    define('TO_EMAIL', 'your@youtube.com'); 
    define('FROM_EMAIL', 'test1@t-online.de');  
    define('FROM_NAME', 'Your Name'); 
    
    
    /**
     * define the body of the email. You can add some shortcode, with this format: %ID%
     * 
     * ID = the id have you insert on the html markup.
     * 
     * e.g.
     * <input type="text" name="email" />
     *       
     * You can add on BODY, this:
     * email: %email%   
     */ 
    define( 'BODY', '%message%<br /><br /><small>email from %name%, email: %email%.</small>' );
    define( 'SUBJECT', 'Stop Smoking Message from %name%' );
    
    
    // here the redirect, when the form is submitted
    define( 'ERROR_URL', 'contact_error.html' );
    define( 'SUCCESS_URL', 'contact_success.html' ); 
    define( 'NOTSENT_URL', 'contact_notsent.html' );           
    
    
    // the message feedback of ajax request
    $msg = array(
        'error' => '<p class="error">Warning! Fill correctly the fields marked in red</p>',
        'success' => '<p class="success">Email sent correctly. Thanks to get in touch us!</p>',
        'not-sent' => '<p class="error">An error has been encountered. Please try again.</p>'
    );      
    // the field required, by name
    $required = array( 'name', 'email', 'message' );
    
    
    /**
     * Send the email.
     * 
     * SERVER-SIDE: the functions redirect to some URL, in base of result of control and send.
     * The urls must be set in the constants above: ERROR_URL, SUCCESS_URL, NOTSENT_URL
     * 
     * CLIENT-SIDE: in js/contact.js, there is already script for real-time checking of fields
     * and for ajax request of send email, that request in this page (sendmail.php) and echo the feedback message.    
     */   
    sendemail();
    // NO NEED EDIT
    function sendemail() 
    {                                
        global $msg, $required;
        if ( isset( $_POST['ajax'] ) )
            $ajax = $_POST['ajax'];
        else
            $ajax = false;
        if ( isset( $_POST['action'] ) AND $_POST['action'] == 'sendmail' ) 
    	{                            
    	    $body = BODY;
    	    $post_data = array_map( 'stripslashes', $_POST );
    // 	    print_r($post_data);
    // 	    die;
    	    foreach ( $required as $id_field ) {
                if( $post_data[$id_field] == '' || is_null( $post_data[$id_field] ) ) {
        	        if ( $ajax )
        	           end_ajax( $msg['error'] );
        	        else
        	    	   redirect( ERROR_URL );
        	    }                       
        	}
    	    if( !is_email( $post_data['email'] ) OR $post_data['email'] == '' ) 
    	        if ( $ajax )
    	           end_ajax( $msg['error'] );
    	        else
        	       redirect( ERROR_URL );
    	    foreach( $post_data as $id => $var )
    	    {
    	    	if( $id == 'message' ) $var = nl2br($var);
    			$body = str_replace( "%$id%", $var, $body );	
    		}
    		$headers  = 'MIME-Version: 1.0' . "\r\n";
    		$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
    		$headers .= 'From: '.FROM_NAME.' <'.FROM_EMAIL.'>' . "\r\n" . 'Reply-To: ' . $post_data['yiw_contact[email]'];
    	    $sendmail = mail( TO_EMAIL, SUBJECT, $body, $headers );
    		if ( $sendmail ) 
    	        if ( $ajax )
    	           end_ajax( $msg['success'] );
    	        else
        	       redirect( SUCCESS_URL );
    	    else
    	        if ( $ajax )
    	           end_ajax( $msg['not-sent'] );
    	        else
        	       redirect( NOTSENT_URL );
    	} 
    }
    
    
    function is_email($email) 
    {
        if (!preg_match("/[a-z0-9][_.a-z0-9-]+@([a-z0-9][0-9a-z-]+.)+([a-z]{2,4})/" , $email))
        {
            return false;
        }
        else
        {
            return true;
        }
    }             
    
    
    function end_ajax( $msg = '' ) {
        echo $msg;
        die;
    }           
    
    
    function redirect( $redirect = '' ) {
        header( 'Location: ' . $redirect );
        die;
    }
    Alles anzeigen

    Kennt sich jemand genau aus, wo ich dies eintragen muss.

    Gruß Manfred
    Ein Sprichwort besagt, "Wenn du nicht aufisst", gibt es morgen schlechtes Wetter.
    Wetterstation: Nexus TE923 HW4


    Homepage

  • silvio
    Diplom-Meteorologe
    Reaktionen
    8
    Punkte
    1.113
    Beiträge
    216
    Website
    https://wetter-kastl.de/
    • 28. Juni 2016 um 14:33
    • #2
    Code
    // email
    define('TO_EMAIL', 'your@youtube.com'); 
    define('FROM_EMAIL', 'test1@t-online.de');  
    define('FROM_NAME', 'Your Name');

    Hier ist alles zu finden

    zum Anfang um es zu verstehen:)


    Grüße Silvio

    Gruß Silvio

    Wetter Kastl

  • Planetarier
    MOD Astronomie
    Reaktionen
    102
    Punkte
    47.732
    Beiträge
    6.652
    Bilder
    44
    • 28. Juni 2016 um 23:10
    • #3

    Hallo Silvio,

    habe dies auf der folgenden Seite eingebaut, aber der Text der in der Webseite eingeben werden soll wird nicht gesendet. Email kommt zwar eine an, aber ohne von wem und Text.

    Code
    // email$empfaenger = "stern1@sternwarte-ehingen.de";$betreff = "Die Mail-Funktion";$from = "";$text = "";mail($empfaenger, $betreff,  $from,  $text);/** * define the body of the email. You can add some shortcode, with this format: %ID% *  * ID = the id have you insert on the html markup. *  * e.g. * <input type="text" name="email" /> *        * You can add on BODY, this: * email: %email%    */ define( 'BODY', '%message%<br /><br /><small>email from %name%, email: %email%.</small>' );define( 'SUBJECT', 'Stop Smoking Message from %name%' );// here the redirect, when the form is submitteddefine( 'ERROR_URL', 'contact_error.html' );define( 'SUCCESS_URL', 'contact_success.html' ); define( 'NOTSENT_URL', 'contact_notsent.html' );           // the message feedback of ajax request$msg = array(    'error' => '<p class="error">Warning! Fill correctly the fields marked in red</p>',    'success' => '<p class="success">Email sent correctly. Thanks to get in touch us!</p>',    'not-sent' => '<p class="error">An error has been encountered. Please try again.</p>');      // the field required, by name$required = array( 'name', 'email', 'message' );/** * Send the email. *  * SERVER-SIDE: the functions redirect to some URL, in base of result of control and send. * The urls must be set in the constants above: ERROR_URL, SUCCESS_URL, NOTSENT_URL *  * CLIENT-SIDE: in js/contact.js, there is already script for real-time checking of fields * and for ajax request of send email, that request in this page (sendmail.php) and echo the feedback message.     */   sendemail();// NO NEED EDITfunction sendemail() {                                    global $msg, $required;    if ( isset( $_POST['ajax'] ) )        $ajax = $_POST['ajax'];    else        $ajax = false;    if ( isset( $_POST['action'] ) AND $_POST['action'] == 'sendmail' ) 	{                            	    $body = BODY;	    $post_data = array_map( 'stripslashes', $_POST );// 	    print_r($post_data);// 	    die;	    foreach ( $required as $id_field ) {            if( $post_data[$id_field] == '' || is_null( $post_data[$id_field] ) ) {    	        if ( $ajax )    	           end_ajax( $msg['error'] );    	        else    	    	   redirect( ERROR_URL );    	    }                           	}	    if( !is_email( $post_data['email'] ) OR $post_data['email'] == '' ) 	        if ( $ajax )	           end_ajax( $msg['error'] );	        else    	       redirect( ERROR_URL );	    foreach( $post_data as $id => $var )	    {	    	if( $id == 'message' ) $var = nl2br($var);			$body = str_replace( "%$id%", $var, $body );			}		$headers  = 'MIME-Version: 1.0' . "\r\n";		$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";		$headers .= 'From: '.FROM_NAME.' <'.FROM_EMAIL.'>' . "\r\n" . 'Reply-To: ' . $post_data['yiw_contact[email]'];	    $sendmail = mail( TO_EMAIL, SUBJECT, $body, $headers );		if ( $sendmail ) 	        if ( $ajax )	           end_ajax( $msg['success'] );	        else    	       redirect( SUCCESS_URL );	    else	        if ( $ajax )	           end_ajax( $msg['not-sent'] );	        else    	       redirect( NOTSENT_URL );	} }function is_email($email) {    if (!preg_match("/[a-z0-9][_.a-z0-9-]+@([a-z0-9][0-9a-z-]+.)+([a-z]{2,4})/" , $email))    {        return false;    }    else    {        return true;    }}             function end_ajax( $msg = '' ) {    echo $msg;    die;}           function redirect( $redirect = '' ) {    header( 'Location: ' . $redirect );    die;}


    Webseite: Html:

    Code
    <h3>Schnell Kontakt</h3>
                            <form id="contact-form-example" class="contact-form" method="post" action="sendmail.php" enctype="multipart/form-data">
                                <div class="usermessagea"></div>
                                <fieldset>
                                    <ul>
                                        <li class="text-field">
                                            <label for="name-example">
                                            <span class="label">Name</span>
                                            </label>
                  <div class="input-prepend"><span class="add-on"><i class="icon-user"></i></span> 
                    <input type="text" name="name" id="name-example" class="required" value="" /></div>
                                            <div class="msg-error"></div>
                                        </li>
                                        <li class="text-field">
                                            <label for="email-example">
                                            <span class="label">Email</span>
                                            </label>
                  <div class="input-prepend"><span class="add-on"><i class="icon-envelope"></i></span> 
                    <input type="text" name="email" id="email-example" class="required email-validate" value="" /></div>
                                            <div class="msg-error"></div>
                                        </li>
                                        <li class="textarea-field">
                                            <label for="message-example">
                                            <span class="label">Message</span>
                                            </label>
                  <div class="input-prepend"><span class="add-on"><i class="icon-pencil"></i></span> 
                    <textarea name="message" id="message-example" rows="8" cols="30" class="required"></textarea></div>
                                            <div class="msg-error"></div>
                                        </li>
                                        <li class="submit-button">
                                            <input type="text" name="yiw_bot" id="yiw_bot" />
                                            <input type="hidden" name="action" value="sendemail" id="action" />
                                            <input type="hidden" name="yiw_referer" value="#" />
                                            <input type="hidden" name="id_form" value="footer" />
                                            <input type="submit" name="yiw_sendemail" value="send message" class="sendmail alignright" />			
                                        </li>
                                    </ul>
                                </fieldset>
                            </form>
    
    
            <script type="text/javascript" language="">
                                var messages_form_footer = {
                                	name: "Insert your name",
                                	email: "Insert your email",
                                	message: "Insert your message"
                                };
    </script>
    Alles anzeigen

    Werde somit wieder nicht schlau daraus.

    Gruß Manfred
    Ein Sprichwort besagt, "Wenn du nicht aufisst", gibt es morgen schlechtes Wetter.
    Wetterstation: Nexus TE923 HW4


    Homepage

  • Werner
    Klimaforscher
    Reaktionen
    43
    Punkte
    7.723
    Beiträge
    1.335
    Bilder
    15
    Einträge
    3
    • 29. Juni 2016 um 07:12
    • #4

    So wie du es aufgebaut hast wird das Script nicht funktionieren. Du hast simple Anweisungen ausgelassen.

    Beispiel

    • define('TO_EMAIL', 'Manfred@youtube.com');
    • define('FROM_EMAIL', 'Manfred@t-online.de');
    • define('FROM_NAME', 'Manfred');

    define muss voran stehen.
    Vorallem mußt du darauf achten, das der Syntax eingehalten wird. Also nichts weglassen oder hinzufügen. Klammern, Semikolon, Anführungsstriche usw.
    // bedeutet, das das was dahinter steht auskommentiert wird.

  • Planetarier
    MOD Astronomie
    Reaktionen
    102
    Punkte
    47.732
    Beiträge
    6.652
    Bilder
    44
    • 29. Juni 2016 um 20:26
    • #5

    @Werner,

    Das Script ist nicht von mir erstellt, sondern ist in der neuen Homepage die ich gestaltet habe mit dabei gewesen. Mir ist schon klar, dass dieses Script nicht funktionieren kann, da dies Fehler enthält. Da ich mich in php nicht auskenne, werde ich mir auch nicht weiter daran dies zu laufen zu bringen. Die Zeit habe ich einfach nicht. Problem war ja dass die Angaben über die Webseite dieses Script aufgerufen wird, aber das geht nicht.

    Gruß Manfred
    Ein Sprichwort besagt, "Wenn du nicht aufisst", gibt es morgen schlechtes Wetter.
    Wetterstation: Nexus TE923 HW4


    Homepage

Radar

Regenradar

Link-Box

Zellenabstand und Zelleninnenabstand in Tabellen
Wegweiser
Kartenanlyse
Webcam
  1. Datenschutzerklärung
  2. Impressum
  3. Nutzungsbedingungen
  4. Kontakt

Partner
Viktor´s Supportboard
Besucherzaehler



Community-Software: WoltLab Suite™ 6.1.25
© Wetter-Board 2004-2026