Contact/bestelformulier ook e-mail naar verzender

Status
Niet open voor verdere reacties.

postvoordennis

Gebruiker
Lid geworden
18 mrt 2008
Berichten
57
Hallo,

Ik ben ook nog een echte beginner, al kom ik er redelijk mee uit de voeten dankzij Google en dit hopelijk ook dit forum ;-)

Ik heb een bestelformulier gemaakt en dat werkt aardig. Als het ingevuld word dan ontvang ik een mailtje met de velden die zijn ingevult. Ik zou alleen willen dat niet alleen ik, maar ook degene invuld een zelfde e-mail ontvangt. Is dit mogelijk?

Hier een voorbeeld van het formulier: KLIK HIER

Het bestaat uit de volgende onderdelen:

besteld.php
bestelformulier.html
formuliertje.text
verzonden.html (naar deze pagina wordt je geleid als het is formulier is verzonden)

Het formuliertje.text ziet er als volgt uit:

>>RECEIVERS>>
mijnemailadres@email.com
>>SUBJECT>>
Bestelling
>>GOTO>>
/hidden/test/verzonden.htm
>>MESSAGE>>

Aantal bloemkolen: ##bestelling##
Verzendwijze: ##verzendwijze##
Naam: ##naam##
Adres: ##adres##
Postcode: ##postcode##
Plaats: ##plaats##
Telefoon: ##telefoon##
E-mailadres: ##email##
Opmerkingen: ##message##

Algemene voorwaarden: ##algemenevoorwaarden##

-----------------------------------------------------------------------
Ik dacht als ik achter mijnemailadres@email.com gewoon ##email## zet, dan word de mail ook verzonden naar degene die het formulier invult. Dit is echter niet het geval.

Weet iemand hoe ik er wél voor kan zorgen dat ook de ander een mailtje ontvangt?

PHP:
<?php
/**
*/
 
	// make sure data is sent in.
	if ( $_SERVER['REQUEST_METHOD'] !== 'POST' || !isset ( $_POST['template'] ) ) {
		redirect();
	}
 
	// make sure the template input is directory safe; no back-skipping.
	if ( strpos ( $_POST['template'], '..' ) !== false ) {
		// contains a reference to '..', trying to change directories. this is NOT allowed.
		redirect();
	}
 
	// make sure this template exists
	if ( !file_exists ( $_POST['template'] . '.txt' ) ) {
		// this appears to be a bad template?
		redirect();
	}
 
	// recover the template we're going to use	
	$aTemplate = file ( $_POST['template'] . '.txt' );
 
	// determine the length of the template
	$iLengthOfTemplate = count ( $aTemplate );
	// at the beginning, we have not yet reached the template itself.
	$bTemplate = false;
	// these will be the receivers of the mail
	$aReceivers = array();
	// this is the mail subject
	$sSubject = 'Default subject';
	// this is the mail template to use.
	$sTemplate = 'Default template';
	// this is where we send the user after he filled in the contact form
	$sGoto = '';
 
	// run over the file to collect the neccesary information
	for ( $i = 0 ; $i < $iLengthOfTemplate ; $i++ ) {
		$sLineValue = $aTemplate[ $i ];
		if ( strpos ( $sLineValue, '>>RECEIVERS>>' ) !== false ) {
			// this is the line that shows we are in the receivers section; skip it over.
			unset ( $aTemplate[ $i ] );
			continue;
		}
		if ( strpos ( $sLineValue, '>>SUBJECT>>' ) !== false ) {
			// we reached the subject. 
			$sSubject = $aTemplate[ $i + 1 ];
			unset ( $aTemplate[ $i ] );
			unset ( $aTemplate[ $i + 1 ] );
			// move to the next entry; since we need to skip over it
			$i++;
			$bTemplate = true;
			continue;
		}
		if ( strpos ( $sLineValue, '>>MESSAGE>>' ) !== false ) {
			// the message starts here			
			unset ( $aTemplate[ $i ] );
			// we have a real template; so drop the dummy
			$sTemplate = '';
			$bTemplate = true;
			continue;
		}
		if ( strpos ( $sLineValue, '>>GOTO>>' ) !== false ) {
			// this is where we go on a success
			$sGoto = $aTemplate[ $i + 1 ];
			unset ( $aTemplate[ $i ] );
			unset ( $aTemplate[ $i + 1 ] );
			// move to the next entry; since we need to skip over it
			$i++;
			continue;
		}		
		if ( $bTemplate ) {
			// this is part of the template
			$sTemplate .= $sLineValue;
		}
		else {
			// this is one of the receivers
			// strip out whitespace, return, newlines, and spaces.			
			$sAddress = str_replace ( array ( "\n", "\r", "\t", " " ), '', $sLineValue );
			$aReceivers[] = $sAddress;
		}
	}
 
	// no receivers, means nothing to do? whatever; success!
	if ( count ( $aReceivers ) == 0 ) {
		success( $sGoto );
	}
 
	// get all the keys and values from the form sent in
	foreach ( $_POST as $sKey => $sValue ) {
		$aSearch[] 	= '##' . $sKey . '##';
		$aReplace[]	= $sValue;
	}
 
	// replace the markers in the template file with their values
	$sTemplate = str_replace ( $aSearch, $aReplace, $sTemplate );
 
	// send the mail to each of these people	
	foreach ( $aReceivers as $sReceiver ) {	
		mail ( $sReceiver, $sSubject, $sTemplate  );
	}
 
	// and we're done.
	success( $sGoto );
 
	/**
	* 	Two functions; one to redirect to the main host for bad requests  and one to send the user back to the previous page it the mail was sent properly
	*/	
	function redirect () {
		header ( 'Location: <a href=\"http://'\" target=\"_blank\" rel=\"nofollow\">http://'</a> . $_SERVER["HTTP_HOST"] . '/' );
		exit;
	}
 
	function success ( $sGoto ) {
		if ( empty ( $sGoto ) ) {
			if ( isset ( $_SERVER["HTTP_REFERER"] ) ) {
				// determine whether a query string was already present
				if ( strpos ( $_SERVER["HTTP_REFERER"], '?' ) !== false ) {
					// it was
					$sSendTo = $_SERVER["HTTP_REFERER"] . '&sent=true';
				}
				else {
					// it wasn't
					$sSendTo = $_SERVER["HTTP_REFERER"] . '?sent=true';		
				}
			}
			else {
				// no referer? send back to index, then.
				$sSendTo = 'http://' . $_SERVER["HTTP_HOST"] . '/?sent=true';
			}
		}
		else {
			// the user set a Goto for after the form. go there now.
			$sSendTo = $sGoto;
		}
 
		header ( 'Location: ' . $sSendTo );
		exit;
	}
 
?>

En het HTML gedeelte:

HTML:
<html>
 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Ik bestel</title>
</head>
<form action="besteld.php" method="post" onsubmit="return FrontPage_Form1_Validator(this)" language="JavaScript" name="FrontPage_Form1" >
			<input type="hidden" name="template" value="formuliertje" />
			<table>
				<tr>
					<!-- these fields are all used in the Template, and they will be sent to you -->
					<td><b><label for="name">Ik bestel:</label></b></td>
					<td><select size="1" name="bestelling">
					<option>1</option>
					<option>2</option>
					<option>3</option>
					<option>4</option>
					<option>5</option>
					<option>6</option>
					<option>7</option>
					<option>8</option>
					<option>9</option>
					<option>10</option>
					</select> bloemkool 2 euro per stuk</td>
				</tr>
				<tr>
					<td height="24"><label for="name"><b>Verzendwijze</b></label><b><label for="name">:</label></b></td>
					<td height="24"><select size="1" name="verzendwijze">
					<option value="Aangetekend 5,95">Aangetekend + € 5,95</option>
					<option value="Reguliere post 2,95">Reguliere post + € 2.95</option>
					</select></td>
				</tr>
				<tr>
					<td><label for="name"><b>Naam</b></label><b><label for="name">:</label></b></td>
					<td>
					<!--webbot bot="Validation" s-data-type="String" b-value-required="TRUE" i-minimum-length="2" --><input type="text" name="naam" value="" size="20" /></td>
				</tr>
				<tr>
					<td><label for="name"><b>Straat en huisnummer </b></label>
					<b><label for="name">:</label></b></td>
					<td>
					<!--webbot bot="Validation" b-value-required="TRUE" i-minimum-length="3" --><input type="text" name="adres" value="" size="20" /></td>
				</tr>
				<tr>
					<td><label for="name"><b>Postcode</b></label><b><label for="name">:</label></b></td>
					<td>
					<!--webbot bot="Validation" s-data-type="String" b-allow-letters="TRUE" b-allow-digits="TRUE" b-allow-whitespace="TRUE" b-value-required="TRUE" i-minimum-length="6" --><input type="text" name="postcode" value="" size="20" /></td>
				</tr>
				<tr>
					<td><label for="name"><b>Plaats</b></label><b><label for="name">:</label></b></td>
					<td>
					<!--webbot bot="Validation" s-data-type="String" b-value-required="TRUE" i-minimum-length="2" --><input type="text" name="plaats" value="" size="20" /></td>
				</tr>
				<tr>
					<td><b><label for="name">Telefoon:</label></b></td>
					<td>
					<!--webbot bot="Validation" s-data-type="String" b-allow-digits="TRUE" b-allow-whitespace="TRUE" s-allow-other-chars="- +" b-value-required="TRUE" i-minimum-length="10" --><input type="text" name="telefoon" value="" size="20" /></td>
				</tr>
				<tr>
					<!-- these fields are all used in the Template, and they will be sent to you -->
					<td><b><label for="name">E-mailadres:</label></b></td>
					<td>
					<!--webbot bot="Validation" s-data-type="String" b-value-required="TRUE" i-minimum-length="5" --><input type="text" name="email" value="" size="20" /></td>
				</tr>
				<tr>
					<td><label for="name"><b>Opmerkingen:</b></label></td>
 
 
					<td width="273"> 
<textarea name="message"rows="5" cols="38"></textarea></td>
				</tr>
				<tr>
					<!-- these fields are all used in the Template, and they will be sent to you -->
					<td colspan="2"><b>
					<input type="radio" value="Akkoord" name="algemenevoorwaarden"> </b>
					Ik ga akkoord met de algemene voorwaarden<br>
					<!--webbot bot="Validation" s-display-name="Algemene voorwaarden" b-value-required="TRUE" --><input type="radio" name="algemenevoorwaarden" value="Niet akkoord"> Ik ga 
					niet akkoord</td>
 
 
				</tr>
				<tr>
					<td colspan="2"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; 
					<input type="submit" value="Verzenden" /></b></td>
				</tr>
			</table>
		</form>
 
<body>
 
</body>
 
</html>

Graag hoor ik van jullie. Alvast bedankt! :)
 
PHP:
// send the mail to each of these people    
    foreach ( $aReceivers as $sReceiver ) { 
        mail ( $sReceiver, $sSubject, $sTemplate  );
    }

Zoals je hier kan zien wordt de e-mail naar alle e-mailadressen in de array "$aReceivers" gestuurd. Dus als je het e-mailadres van de "invuller" toevoegt aan die array
PHP:
$aReceivers[] = $_POST['email']
zou die ook de e-mail moeten krijgen.

Werkt het script überhaupt wel? Ik vind regel 111 er niet goed uitzien. Ten eerste ziet zo'n regel er meestal zo uit
PHP:
header('Location: http://www.example.com/');
dus zonder HTML-code. Ten tweede kan je aan de kleuren zien dat de string niet wordt afgesloten.
 
Laatst bewerkt:
Hoi supersnail, bedankt voor je antwoord! Ik ben echt een super beginner, dus snap niet helemaal wat ik moet veranderen.

Moet ik deze code:
PHP:
// send the mail to each of these people    
    foreach ( $aReceivers as $sReceiver ) { 
        mail ( $sReceiver, $sSubject, $sTemplate  );
    }

veranderen zodat die als volgt wordt? Ik snap neit precies waar ik $aReceivers[] = $_POST['email'] bij moet zetten.

Zoals deze???

PHP:
// send the mail to each of these people    
    foreach ( $aReceivers as $sReceiver ) { 
        mail ( $sReceiver, $sSubject, $sTemplate  );
    }
$aReceivers[] = $_POST['email']

Graag hoor ik van je! Het script werkt wel gewoon goed, ik heb het door google eens gevonden.

Groeten Dennis
 
Waar je het precies zet maakt niet zoveel uit. Wel moet het voor de "foreach" komen. Je zou het dus zo kunnen doen
PHP:
// send the mail to each of these people    
    $aReceivers[] = $_POST['email']
    foreach ( $aReceivers as $sReceiver ) { 
        mail ( $sReceiver, $sSubject, $sTemplate  );
    }
 
Als ik dat doe dan krijg ik niet meer de bevestigingspagina te zien van: uw bestelling is verzonden.

Daarnaast ontvang zowel IK als de invoerder van het formulier geen e-mail. Dus dan werkt die helemaal niet meer :-S
 
Je hebt gelijk. Er moet nog een ';' (puntkomma) achter.

PHP:
// send the mail to each of these people    
    $aReceivers[] = $_POST['email'];
    foreach ( $aReceivers as $sReceiver ) { 
        mail ( $sReceiver, $sSubject, $sTemplate  );
    }
 
@ Dennis,

Als je error_reporting en display_errors aan had staan, dan zou de parser direct aangeven waar de fout zit. Is eigenlijk wel een vereiste dat je dat in ieder geval in je test- / ontwikkelstadium aan hebt staan.

Zet dit maar helemaal bovenaan je pagina:

PHP:
<?php

  error_reporting ( E_ALL );
  ini_set ( 'display_errors', 1 );

?>
 
Helemaal super hij werkt! :thumb:

Je ziet nu tevens als afzender als je de e-mail krijgt het volgende: anonymous@ server86.hosting2go.nl

Vrij logisch, want via die server wordt de mail verstuurd. Is het toch nog mogelijk dat de klant een naam in beeld ziet? Bijvoorbeeld: De bloemkolenwinkel.

Dit staat wat netter dan een dergelijke server:)

Nogmaals super bedankt!

Groeten Dennis
 
Maak van:

PHP:
 mail ( $sReceiver, $sSubject, $sTemplate  );

eens:

PHP:
 mail ( $sReceiver, $sSubject, $sTemplate, 'From: De Bloemkolenwinkel <anonymous@server86.hosting2go.nl>' );
 
Al het bovenstaande is nu werkzaam en die problemen zijn nu opgelost. Ik heb alleen nog een vraag of het volgende mogelijk is:

Het volgende formulier is makkelijk in gebruik als je slechts één product hebt: klik hier

Nu geeft dit wel een probleem als je meerdere producten hebt en daarnaast krijgt de klant niet te zien wat het totaalbedrag is.

Is het mogelijk om dit formulier om te bouwen zodat het blijft functioneren zoals voorheen, maar dan met een volgend soort element erin: klik hier

Graag hoor ik van jullie.

Groeten Dennis
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan