Newsletteranmeldung

RuthG

Mitglied
Hallo,

ich möchte gerne in mein Bestellformular die Möglichkeit einbauen sich für den Newsletter anzumelden. Jetzt habe ich mir überlegt eine zweite If-Anweisung einzubauen:

PHP:
<?php
if($newsletter == "accept")
  {
    mail($an_news,$betreff_news,$mail,$from);
  }
  ?>

Das Formularfeld hat den value "accept" wenn es angeklickt wird. Leider kann er scheitert es am Vergleich, da kein Mail weggeschickt wird. Was hab ich denn nicht beachtet?

Danke, LG Ruth
 
Normalerweise spricht man Formularfelder so an:
PHP:
if( $_POST["newsletter"] == "accept" ){
  //do something
}
 
PHP:
$betreff_news = "Subscribe Newsletter";
$from = "From: " .$company ." " .$name  ."<" .$mail .">\n";
$from .= "Reply-To: " .$mail ."\n";
$from .= "Content-Type: text/html\n";

$mail ist die E-Mailadresse die ins Formular eingebene wurde

@timestamp:
das hab ich jetzt ausprobiert, ändert aber leider nichts daran das er accept nicht anerkennt :(

Hab sicherheitshalber eine else angabe angegeben um zu sehen ob überhaupt was passiert und es wird mir jedes mal diese angezeigt.
 
Hi

Das hier ist eigentlich die übliche Variante:
HTML:
<form method="post" action="./index.php">
<input type="submit" name="myButton" value="myValue" />
</form>

PHP:
error_reporting(E_ALL); //Fehlermeldungen aktivieren
var_dump($_POST); //Inhalt von $_POST ausgeben
if( isset($_POST["myButton"]) ){ //prüfen ob die Variable existiert
  echo "Button gedrückt";
}
 
Mein Formular im gesamten sieht so aus:
HTML:
<div id="formular">
                <form action="formular.php" method="post" onSubmit="window.open('about:blank','popup','width=900,height=600'); return true;" name="Kontakt" target="popup">
                     
                    <p id="first">This is  <input type="radio" class="checkbox" name="what" value="order"/>an <b>order</b> or<input type="radio" class="checkbox" name="what" value="request"/> a <b>request</b></p>     
                  <fieldset>
                  <legend>General Information</legend>
                        <table id="personal">  
                        <tr><td class="imp"><input type="radio" class="checkbox" name="who" value="privat"/>Private person or 
                          <input type="radio"class="checkbox" name="who" value="company"/>
                          Company *</td>
                          <td class="imp">Have you already ordered from us?<input type="radio" class="checkbox" name="customer" value="yes"/>Yes 
                          <input type="radio"class="checkbox" name="customer" value="no"/>
                          No *</td>
                        </tr>    
                          
                        <tr><td><h4><label for="company">Company Name:</label></h4>
                        <p><input class="feld" id="trade" type="text" name="company" size="50" maxlength="150"/></p>
                        <p><input class="feld" id="trade" type="text" name="company_extra" size="50" maxlength="150"/></p></td>
                        
                        <td><h4><label for="number">Customer Number (if available): </label></h4>
                        <p><input class="feld" id="trade" type="text" name="number" size="50" maxlength="150"/></p></td></tr>
                                   
                        
                        <tr><td>
                        <h4 class="imp">Phone Number: *</h4>
                        <p><input class="feld" type="text" name="phone" size="50" maxlength="150" /></p>
                        <h4><label for="fax">Fax Number:</label></h4>
                        <p><input class="feld" type="text" name="fax" size="50" maxlength="150" /></p></td>
                        
                        <td><h4 class="imp">Contact Person: *</h4>
                        <p><input class="feld"  id="name" type="text" name="name" size="50" maxlength="150" /></p>
                        <h4 class="imp">e-mail: *</h4>
                        <p><input class="feld" id="mail" type="text" name="mail" size="50" maxlength="150" /></p></td></tr>
                        
                        <tr><td><h4>Invoice Address:</h4>
                        <p><input class="feld" type="text" name="bill_street" size="50" maxlength="150" value="street name & number" /></p>
                        <p><input class="feld" type="text" name="bill_add" size="50" maxlength="150" value="" /></p>
                        <p><input class="feld" type="text" name="bill_city" size="50" maxlength="150" value="city" /></p>
                        <p><input class="feld" type="text" name="bill_country" size="50" maxlength="150" value="country" /></p>
                        <p><input class="feld" type="text" name="bill_zip" size="50" maxlength="150" value="zip" /></p>
                        <h4 class="imp">VAT (European Customers):*</h4>
                        <p><input class="feld" type="text" name="vat" size="50" maxlength="150"/></p>
                        </td>
                        
            
                       <td><h4>Shipping Address: <small>(if is different to invoice address) </small></h4>
                        <p><input class="feld" type="text" name="ship_street" size="50" maxlength="150" value="street name & number" /></p>
                        <p><input class="feld" type="text" name="ship_add" size="50" maxlength="150" value="" /></p>
                        <p><input class="feld" type="text" name="ship_city" size="50" maxlength="150" value="city" /></p>
                        <p><input class="feld" type="text" name="ship_country" size="50" maxlength="150" value="country" /></p>
                        <p><input class="feld" type="text" name="ship_zip" size="50" maxlength="150" value="zip" /></p></td></tr>
                  </table>
                  </fieldset>   
                         
                         <fieldset>
                         <legend>Order</legend>
                                    
                         
                         <ul id="order"><li class="units">Units</li><li class="article">Article</li><li class="note">Note</li></ul>
                         <div class="clear" >
                                            <input class="feld units" type="text" name="units[]" size="7" maxlength="7" />
                                            <input class="feld article" type="text" name="article[]" size="80" maxlength="100" />
                                            <input class="feld note" type="text" name="note[]" size="60" maxlength="100" />
                                            <input type="button" class="button_zeile" value="+" onClick="clone_this(this)" />
                          </div>
                         
                         
                         
                         
                   		<div id="payment">
                                 <h3 class="abstandvor">Payment Method</h3>
                                 <p><input type="radio" class="checkbox" name="pay" value="creditcard"/>Creditcard 
                                 <input type="radio"class="checkbox" name="pay" value="advanced"/>in advance by banktransfer
                           		 
                                 
                                 <div class="abstandvor"><p>We accept following credit cards</p>
                                 <p class="abstandvor">
                                 <input type="radio" class="checkbox" name="cc" value="visa"/><img src="pic/visa.png"alt="Visa">
                                 <input type="radio" class="checkbox" name="cc" value="mastercard"/><img src="pic/mastercard.png" alt="MasterCard">
                                 <input type="radio" class="checkbox" name="cc" value="amex"/><img src="pic/amex.png" alt="Amex"></p>
                                 
                                 
                                 </div>
                         </div>
                         
                         <div class="abstandvor"><h3>Preferred Currency:</h3>
                         <p> <input type="radio" class="checkbox" name="currency" value="EUR"/>EUR or <input type="radio" class="checkbox" name="currency" value="EUR"/>USD</div>
                                 
                                <div class="abstandvor"><h3>Preferred shipping method</h3>
                                <p>	<input type="radio" class="checkbox" name="deliverer" value="fedex"/>FedEx
                                	<input type="radio" class="checkbox" name="deliverer" value="ups"/>UPS
                                    <input type="radio" class="checkbox" name="deliverer" value="dhl"/>DHL
                                    <input type="radio" class="checkbox" name="deliverer" value="ems"/>EMS
                                    <input type="radio" class="checkbox" name="deliverer" value="parcelpost"/>Parcel Post
                                    <input type="radio" class="checkbox" name="deliverer" value="other"/>Other: <input class="feld" type="text" name="other" size="25" maxlength="100">
                                </p>
                         <p>Account number if available: <input id="shipping" class="feld" type="text" name="account" size="50" maxlength="100"></p></div>
                                 
                         
                                 
                          </fieldset>     
                            
                        <fieldset>
                        <legend class="imp">Message *</legend>
                        <textarea  id="message" class="feld" name="message" rows="5" cols="115" wrap="soft"></textarea>
                        </fieldset>
                        
                        <fieldset>
                       
                        <!--Hier ist der Teil für den Newsletter. Soll nur zusätzlich zum normalen Newsletter eintragen sein -->
                        <p class="abstandvor"><input class="checkbox" type="checkbox" name="newsletter" value="accept">Please, click here to get our newsletter.</p>
                        <!-- Ende Newsletter -->
                        <p class="abstandvor"><input class="checkbox" type="checkbox" name="condition" value="accept">Please, click here to accept the <a href="conditions.pdf">terms and conditions.</a>*</p>
                            
                        <p> <input type="submit" class="button" name="senden" value="Send" />
                           <!-- <input type="reset" class="button" name="reset" value="Reset" /></p>-->
                        </fieldset>
                        
                        </form>
                    </div><!-- Ende Formular -->


Das ist die Auswertung dazu:

PHP:
<?php
$fehler ="";
$nz = chr(13);
$who = $_POST['who'];
$customer= $_POST['customer'];
$company = $_POST['company'];
$company_extra = $_POST['company_extra'];
$name= $_POST['name'];
$number= $_POST['number'];
$phone= $_POST['phone'];
$fax= $_POST['fax'];
$mail= $_POST['mail'];
$bill_street= $_POST['bill_street'];
$bill_city= $_POST['bill_city'];
$bill_add= $_POST['bill_add'];
$bill_country= $_POST['bill_country'];
$bill_zip= $_POST['bill_zip'];
$ship_street= $_POST['ship_street'];
$ship_city= $_POST['ship_city'];
$ship_add= $_POST['ship_add'];
$ship_country= $_POST['ship_country'];
$ship_zip= $_POST['ship_zip'];
$vat= $_POST['vat'];
$cc= $_POST['cc'];
$currency= $_POST['currency'];
$deliverer= $_POST['deliverer'];
$other= $_POST['other'];
$account= $_POST['account'];
$units= $_POST['units'];
$article= $_POST['article'];
$note= $_POST['note'];
$message= $_POST['message'];
$pay= $_POST['pay'];
$shipping= $_POST['shipping'];
$what= $_POST['what'];
$newsletter= $_POST['newsletter'];
$condition= $_POST['condition'];



if (empty($who)) $fehler .= "<li>Please, fill if you are a private person or a company. </li>";
if (empty($customer)) $fehler .= "<li>Please, check if you have already ordered from us.</li>";
if (empty($name)) $fehler .= "<li>Please, fill in your name. </li>";
if (empty($phone)) $fehler .= "<li>Please, fill in your phone number. </li>";
if (empty($mail)) $fehler .= "<li>Please, fill in your mail adress. </li>";
if (empty($message)) $fehler .= "<li>Please, tell us how we can help you. The Messagebox is empty. </li>";
if (empty($what)) $fehler .= "<li>Please, tell us if this is a order or a request. </li>";
if (empty($condition)) $fehler .= "<li>Please, read our conditions and check the box. </li>";
if (empty($fehler)) {



	if(is_array($_POST['units'])){
  $units = "";
  for($i=0; $i<count($_POST['units']); $i++){
    $units .= "- " . $_POST['units'][$i] . " Einheiten " . $_POST['article'][$i] . " (" . $_POST['note'][$i] . ")<br />";
  }
}else{
  $units= "- " . $_POST['units'] . " Einheiten " . $_POST['article'] . " (" . $_POST['note'] . ")";
}



	$an = "name@xyz.com";
	$an_news = "newsletter@xyzcom";
	$betreff = "Subject: " .$what .", " .$company ." " .$name;
	$betreff_news = "Subscribe Newsletter";
	$from = "From: " .$company ." " .$name  ."<" .$mail .">\n";
	$from .= "Reply-To: " .$mail ."\n";
	$from .= "Content-Type: text/html\n";
	$datum = "Datum: ".date("j.n.Y");
	$zeit = "Zeit: ".date("H:i").$nz;
	$von = "Von: ".$name."<".$mail.">".$nz;
	$bill_adress = "<td><b>Billing Adress:</b><p>" .$bill_street ." </p><p>" .bill_add ." </p><p>" .$bill_city ." </p><p>" .$bill_country ." </p><p>" .$bill_zip ."</p></td>";
	$ship_adress = "<td><b>Shipping Adress:</b><p>" .$ship_street ." </p><p>" .ship_add ." </p><p>".$ship_city ." </p><p>" .$ship_country ." </p><p>" .$ship_zip ."</p></td>";
	$message = "<p><b>Message:</b> " .$message ."</p>";
	$what = "<p><b>Order or Request:</b> " .$what ."</p>";
	$condition = "<p><b>Condition:</b> " .$condition ."</p>";
	$personal = "<td><b>Company or Privat: </b>" .$who ."</td> <td><b>Already customer?</b> ".$customer ."</td></tr><tr><td><b>Customer Number:</b> " .$number ."</td></tr><tr><td><b>Company: </b>" .$company ." (" .$company_extra .")" ."</td><td><b>Name:</b> " .$name ."</td></tr><tr><td><b>Mail:</b> " .$mail ."</td> <td><b>Phone:</b> " .$phone ."</tr><tr></td> <td><b>Fax:</b> " .$fax ."</td></tr><tr>" .$bill_adress .$ship_adress ;
	$order = "<b>Order:</b> <p>" .$units ."</p>";
	$text='<!DOCTYPE html PUBLIC "-//W3C//DTD html 4.01 Transitional//EN">';
    $text.='<html>';
    $text.='<head>';
	$text.="<style>	body {	font-family: Verdana, Georgia, Arial, Helvetica, sans-serif;	font-size: 1em;	text-align:left;	line-height:140%}

	p {margin:0px}
	
	table {
	font-size: 1em; margin-top:10px}
	
	table tr {margin-top: 10px}
	table td { width:400px}
	
	</style>";
    $text.='</head>';
    $text.='<body>';
    $text.= "<p><td>$datum, $zeit </p>";
	$text.= "<table><tr>$personal</tr>";
	$text.= "<tr><td><b>VAT: </b>$vat</td></tr>";
	$text.= "<tr><td><b>Payment: </b>$pay</td><td><b>Creditcard: </b>$cc</td></tr>";
	$text.= "<tr><td><b>Currency: </b>$currency</td></tr>";
	$text.= "<tr><td><b>Deliverer: </b>$deliverer </td><td> $other</td></tr>";
	$text.= "<tr><td><b>Account Number: </b>$account </td></tr>";
	$text.= "<tr><td colspan=\"2\">$message <td></tr>";
	$text.= "<tr><td> $order </td></tr>";
	$text.= "<tr><td> <b>Newsletter:</b> $newsletter </td></tr>";
	$text.= "</table>";
	$text.='</body>';
    $text.='</html>'; 
	$titel = "Thank you for your Mail. You will get a confirmation within the next days.";
	
	mail($an,$betreff,$text,$from);
	mail($mail,$betreff,$text,$from);
	} else  $titel = "Sorry, but there is a mistake.";
	
	if($_POST["newsletter"] == "accept" )
  {
    mail($an_news,$betreff_news,$mail,$from);
  }echo  $titel = "Sorry, you didn't accept the newsletter.";

	
	?>

<?php

  ?>

<html>
	
	<style type="text/css">
	body {
	font-family: Verdana, Georgia, Arial, Helvetica, sans-serif;
	font-size: 0.85em;
	text-align:left;
	line-height:140%}

	p {margin:0px}
	
	table {
	font-size: 1em; margin-top:10px}
	
	table tr {margin-top: 10px}
	table td { width:400px}
	
	</style>
    
	<head>
	<title><?=$titel?></title>
	</head>
    
	<body>
	<?php
		if (empty($fehler)) {
		$text = strip_tags($text);
		$text = htmlentities($text);
		$text = str_replace($nz,"<br>",$text);
		echo "<p><b>Thank you for your Mail. You will get a confirmation within the next days.</b></p>";
		echo "<p><td>$datum, $zeit </p>";
		echo "<table><tr>$personal</tr>";
		echo "<tr><td><b>VAT: </b>$vat</td></tr>";
		echo "<tr><td><b>Payment: </b>$pay</td><td><b>Creditcard: </b>$cc</td></tr>";
		echo "<tr><td><b>Currency: </b>$currency</td></tr>";
		echo "<tr><td><b>Deliverer: </b>$deliverer </td><td> $other</td></tr>";
		echo "<tr><td><b>Account Number: </b>$account </td></tr>";
		echo "<tr><td colspan=\"2\">$message <td></tr>";
		echo "<tr><td> $order </td></tr>";
		echo "<tr><td> <b>Newsletter:</b> $newsletter  </td></tr>";
		echo "</table>";
	}	else {
		echo "<p>Sorry, your message could not be send:";
		echo "<ul>$fehler</ul>";
		echo "</p>";
		
	}
	?>
	
	</body>
	</html>
 
Mal vorweg: Du solltest dir dringend einen etwas schöneren Stil angewöhnen ( Einrückungen etc. ) das erleichtert vieles ( wie z.B. die Fehlersuche)

Ich hab deinen Code jetzt mal etwas abgeändert (mail durch echo ersetzt ) bei mir getestet und erhalte folgende Ausgabe:
PHP:
Notice: Undefined index: shipping in D:\wamp\www\Proj\test.php  on line 163

Notice: Use of undefined constant bill_add - assumed 'bill_add' in D:\wamp\www\Proj\test.php on line 201

Notice: Use of undefined constant ship_add - assumed 'ship_add' in D:\wamp\www\Proj\test.php on line 202
sending 2 mails 
sending newsletter mail

Mit anderen Worten es funktioniert. ( von den notices mal abgesehen)
Mir ist allerdings aufgefallen das du die Fehlermeldung in jedem Fall ausgibst. Richtigerweise müsste es so aussehen:
PHP:
if($_POST["newsletter"] == "accept" )
	  {
		mail($an_news,$betreff_news,$mail,$from);		
	  }else{
                     echo  $titel = "Sorry, you didn't accept the newsletter."; 
         }
 
Zurück