PHP email is sent but data isn't displayed everywhere

So, I am trying to create a contactform. Customers can add products to a shoppingcart. This is done using sessions. the session productname stores the name of the product, obviously.

I need the code to check if it contains the lastname and email. If not, an error message’s displayed. Then it checks the captcha. If all is right, it needs to send 2 emails, one to my emailadress ($LMEY_email) and another to the customer’s email. Both emails should contain the data that’s filled in.

Now the code I have does sent an email, it only doesn’t contain the data, except for one. The $title contains $lastname, this works just fine when the email is send. If you scroll down the code, the same $lastname inside the $message doesn’t give me any data.

Also, if I keep the code like this, I get the message:

[php]Fatal error: Call to undefined function SendEmail() in /home/./././public_html/folder/pagename.php on line XXX[/php]

which I don’t understand, because this function is right beneath the line that’s calling the function.

If I swap positions (so first the function, second the call) the warning disappears.

What do I need to change to get the data inside the email and get rid of the warning?

The code:
[php]
session_start();

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

define("PRODUCTNAME", 1);
$LMEY_email ='[email protected]';

$cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : '';
$itemcount = isset($_SESSION['itemcount']) ? $_SESSION['itemcount'] : 0;
if ($itemcount == 0)
{
   header("Location: "."error.php?msg=".rawurlencode("Voeg aub eerst evenementen toe voordat u uw     informatieaanvraag afrondt."));
   $strHTML = "<font class='bewaardeItems'>U heeft nog geen evenementen aangeklikt.</font>";
   exit;
} 

$errors = '';
$firstname = '';
$lastname = '';
$straatnaam = '';
$huisnummer = '';
$postcode = '';
$woonplaats = '';
$land = '';
$visitor_email = '';
$telefoonnummer = '';
$deelnemers = '';
$optiedatum = '';
$opmerkingen = '';
$straatnaam_feestlocatie = '';
$huisnummer_feestlocatie = '';
$postcode_feestlocatie = '';
$plaats_feestlocatie = '';
$land_feestlocatie = '';

$strHTML = "<div style=\"overflow:auto; height=358px;\">"."\n";
   $strHTML .= "<table border=\"0\" cellpadding=\"3\" cellspacing=\"2\" width=\"100%\">"."\n";

   for ($i=0; $i<$itemcount; $i++)
   {
      $strHTML .= "<tr>"."\n";
      $strHTML .= "<td><a href='".$cart[PRODUCTNAME][$i]['savelink']."'     class='bewaardeItems'>".$cart[PRODUCTNAME][$i]['eventnaam']."</a></td>"."\n";
      $strHTML .= "</tr>"."\n";
   }

   $strHTML .= "</table>"."\n";
   $strHTML .= "</div>"."\n";

if(isset($_POST['submit']))
{
	
	$firstname = $_POST['firstname'];
	$lastname = $_POST['lastname'];
	$straatnaam = $_POST['straatnaam'];
	$huisnummer = $_POST['huisnummer'];
	$postcode = $_POST['postcode'];
	$woonplaats = $_POST['woonplaats'];
	$land = $_POST['land'];
	$visitor_email = $_POST['email'];
	$telefoonnummer = $_POST['telefoonnummer'];
	$deelnemers = $_POST['deelnemers'];
	$optiedatum = $_POST['optiedatum'];
	$opmerkingen = $_POST['opmerkingen'];
    $straatnaam_feestlocatie = $_POST['straatnaam_feestlocatie'];
	$huisnummer_feestlocatie = $_POST['huisnummer_feestlocatie'];
	$postcode_feestlocatie = $_POST['postcode_feestlocatie'];
	$plaats_feestlocatie = $_POST['plaats_feestlocatie'];
	$land_feestlocatie = $_POST['land_feestlocatie'];
	///------------Do Validations-------------
	if(empty($lastname)||empty($visitor_email))
	{
		$errors .= "\n Naam en email zijn verplicht. ";	
	}
	if(IsInjected($visitor_email))
	{
		$errors .= "\n Ongeldige email!";
	}
	if(empty($_SESSION['6_letters_code'] ) ||
	  strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
	{
		$errors .= "\n De beveiligingscode komt niet overeen!";
	}
	
	if(empty($errors))
	{
		//verzend de mail vanaf hier
		if (!isset($visitor_email))
{
   header("Location: "."error.php?msg=".rawurlencode("We hebben uw gegevens niet ontvangen,     probeert u het aub. nogmaals."));
   exit;
} 

// create an ID
$orderid = strtotime("now").$_SERVER['REMOTE_ADDR']; 
$orderid = str_replace(".", "", "$orderid"); 

// create timestamp
$timestamp = date("Y-m-d H:i:s");

// mail data to customer
$subject = "Informatie aanvraag Entertain You events"; 
$title = "Wij hebben uw aanvraag ontvangen, waarvoor hartelijk dank! Wij streven er naar om u     binnen 2 werkdagen van antwoord te voorzien. Ondanks dat deze mail automatisch is opgesteld, kunt u eventuele vragen stellen door deze mail te beantwoorden.";
SendEmail($visitor_email, $subject, $title, $orderid, $timestamp, true);

// mail data to me
$subject = "Nieuwe informatie aanvraag";
$title = "Dhr. / Mevr. ".$lastname." heeft het contactformulier ingevuld. De volgende gegevens     zijn daarbij verzonden:";
SendEmail($LMEY_email, $subject, $title, $orderid, $timestamp, false);

function SendEmail($mailto, $subject, $title, $orderid, $timestamp, $maskcardno)
{
   $header  = "From: Entertain You Events"."\r\n"; 
   $header .= "Reply-To: ".$LMEY_email."\r\n"; 
   $header .= "MIME-Version: 1.0"."\r\n"; 
   $header .= "Content-Type: text/plain; charset=utf-8"."\r\n"; 
   $header .= "Content-Transfer-Encoding: 8bit"."\r\n"; 
   $header .= "X-Mailer: PHP v".phpversion(); 

   $message = $title."\r\n"."\r\n";
   $message .= "Aanvraagnummer: LMEY".$orderid."\r\n";
   $message .= "Aanvraagdatum: ".$timestamp."\r\n"."\r\n";

   $message .= "Persoonlijke gegevens:"."\r\n";
   $message .= "Voornaam: ".$firstname."\r\n";
   $message .= "Achternaam: ".$lastname."\r\n";
   $message .= "Email: ".$visitor_email."\r\n";
   $message .= "Adres: ".$straatnaam." - ".$huisnummer."\r\n";
   $message .= "Woonplaats: ".$woonplaats."\r\n";
   $message .= "Postcode: ".$postcode."\r\n";
   $message .= "Land: ".$land."\r\n";
   $message .= "Telefoonnummer: ".$telefoonnummer."\r\n"."\r\n";

   $message .= "Informatie-aanvraag over de volgende evenementen:"."\r\n"."\r\n";
   $message .= "======================================================="."\r\n";

   $itemcount = $_SESSION['itemcount'];
   $cart = $_SESSION['cart'];

   for ($i=0; $i<$itemcount; $i++)
   {
      $message .= $cart[PRODUCTNAME][$i]."\t";
      $message .= "\r\n";
   }

   $message .= "======================================================="."\r\n";
   $message .= "\r\n"."\r\n";

   mail($mailto, $subject, stripslashes($message), $header); 
}

header("Location: "."succes.php?msg=".rawurlencode("Succes!"));
	}
}

[/php]

Allright, I’ve placed the function outside the if-statement. One problem down. Still it doesn’t return any data in the email except for the one inside the $title

Well, a quick review of the code points out one issue right off the top.

Functions are usually defined at the top of the page. Most programmers place all of the functions
either in a separate file and include it at the top of each page or if the function is only for this one
page, they place it at the top right after starting the session. The error you are receiving is due to
the function not being created before you use it. It is sort of like, put on your pants, then get the
pants out of the closet. (Doesn’t work that way…)

Since I see you use the email function more than once in your code, you still need to use it, so to
fix it just move the function up to the top of the page right after starting your session and setting
the full error options… Should fix it… Good luck and let us know if it doesn’t…

Oh, also, you might want to read up on email headers. Two small comments on this section.

First, it is never a good practice to use a PHP command as a variable name. Since “header” is a PHP
command, I would never use it for a variable name. Confuses other who might read your code. I would
change that variable name to $email_headers or even just $headers. “headers” is different enough
from “header” to make the reader see a difference, but, “email_headers” is better.

Next, the header coding that you are using is currently:
[php]
$header .= “Content-Type: text/plain; charset=utf-8”."\r\n";
$header .= “Content-Transfer-Encoding: 8bit”."\r\n";
$header .= “X-Mailer: PHP v”.phpversion();
[/php]
The last line only tells people what programming language is sending this email. I no longer use that so
that the person getting the mail does not know I am using PHP. Why tell them? This line is not needed.
The transfer-encoding is set to 8 bits per char? Unless you are sending to a very old computer system
or using your own server, that line is not needed. The Content-Type is set to plain text. You might want
to think about using HTML instead. Think of your contact-page on your website. You can send an email
that looks just like that. There are only a few rules when sending out HTML emails. ALL CSS must be
inline and no programming. It just makes the emails look so much more professional… If you do decide
to create an HTML version, start a new post and we can help you with it…

Just more knowledge to help you with this project. Good luck…

:slight_smile:

I’ve moved the code all the way to the top, directly under the [php]session_start[/php] but this gives an error on the array.

When I move the code beneath the
[php]$cart = isset($_SESSION[‘cart’]) ? $_SESSION[‘cart’] : ‘’;
$itemcount = isset($_SESSION[‘itemcount’]) ? $_SESSION[‘itemcount’] : 0;[/php]
the array is displayed correctly.

The email is sent, still with the most important data missing.

It does display
[php]$orderid
$timestamp[/php]
which are inside the function. Those are sent inside the email.

The $lastname which is in the $title works too.
All the other fields inside of the function are empty.

Also, the reason why I call the email function twice is because I want the code to send the data to me and a confirmation to the customer. Both email have a different $title, but the same data. I receive an email when I push the submit button. The customer doesn’t.

Why is just a small part of the data working as it should and how is it possible that the $title can echo the $lastname but the $message can’t, while this same $message does read the $timestamp and $orderid

also,

[php]header("Location: ".“succes.php?msg=”.rawurlencode(“Succes!”));[/php]

doesn’t work. When I push the submit button the page returns to the same page.

Well, you keep showing us little pieces of the routine. Hard to solve it for you without seeing it all.
Please post from the session_start to where it emails the messages. Please place inside PHP tags.

As far as the header goes, it is formatted wrong. The standard is:
header(“Location: somepage-to-go-to.php”);
Yours is like:
header("Location: somepage-to-go-to.php;
It does not end… It should be like this:
[php]
header(“Location: succes.php?msg=’” . rawurlencode(“Succes!”) . “’”);
[/php]
(NOTE: you do not need the rawurlencode for that text, it is okay to use it. Also, note the end of the msg
text… It is a single quote inside of two double quotes… ! )
This would work, too…
[php]
header("Location: succes.php?msg=‘Succes!’ ");
[/php]
Hope that helped.

allright, the complete code, for as far as I have it now. I’ve changed the header already. I didn’t change the email format yet. I am going to change this to html but for now let’s stick with the plain text. Functionality comes before beauty for me (at least for the programming, let’s keep that clear ;))

[php]session_start();

ini_set(‘display_errors’, 1);
error_reporting(E_ALL);

define(“PRODUCTNAME”, 1);
$LMEY_email =‘[email protected]’;

$cart = isset($_SESSION[‘cart’]) ? $_SESSION[‘cart’] : ‘’;
$itemcount = isset($_SESSION[‘itemcount’]) ? $_SESSION[‘itemcount’] : 0;

function SendEmail($mailto, $subject, $title, $orderid, $timestamp, $maskcardno)
{
$email_headers = “From: Entertain You Events”."\r\n";
$email_headers .= “Reply-To: “.$LMEY_email.”\r\n”;
$email_headers .= “MIME-Version: 1.0”."\r\n";
$email_headers .= “Content-Type: text/plain; charset=utf-8”."\r\n";

$message = $title."\r\n"."\r\n";
$message .= “Aanvraagnummer: LMEY”.$orderid."\r\n";
$message .= “Aanvraagdatum: “.$timestamp.”\r\n”."\r\n";

$message .= “Persoonlijke gegevens:”."\r\n";
$message .= “Voornaam: “.$firstname.”\r\n”;
$message .= “Achternaam: “.$lastname.”\r\n”;
$message .= “Email: “.$visitor_email.”\r\n”;
$message .= “Adres: “.$straatnaam.” “.$huisnummer.”\r\n”;
$message .= “Woonplaats: “.$woonplaats.”\r\n”;
$message .= “Postcode: “.$postcode.”\r\n”;
$message .= “Land: “.$land.”\r\n”;
$message .= “Telefoonnummer: “.$telefoonnummer.”\r\n”."\r\n";

$message .= “Adres feestlocatie:”."\r\n";
$message .= “Naam: “.$_SESSION[‘shipname’].”\r\n”;
$message .= “Adres: “.$_SESSION[‘shipaddress’].”\r\n”;
$message .= “Woonplaats: “.$_SESSION[‘shipcity’].”\r\n”;
$message .= “Postcode: “.$_SESSION[‘shipzip’].”\r\n”;
$message .= “Land: “.$_SESSION[‘shipcountry’].”\r\n”."\r\n";

$message .= “Overige info:”."\r\n";
$message .= “Optie datum: “.$_SESSION[‘optieDatum’].”\r\n”;
$message .= “Verwachte aantal deelnemers: “.$_SESSION[‘verwachtAantal’].”\r\n”."\r\n";

$message .= “Informatie-aanvraag over de volgende evenementen:”."\r\n"."\r\n";
$message .= “=======================================================”."\r\n";

$itemcount = $_SESSION[‘itemcount’];
$cart = $_SESSION[‘cart’];

for ($i=0; $i<$itemcount; $i++)
{
$message .= $cart[PRODUCTNAME][$i][‘eventnaam’]."\t";
$message .= “\r\n”;
}

$message .= “=======================================================”."\r\n";
$message .= “\r\n”."\r\n";

mail($mailto, $subject, stripslashes($message), $email_headers);
}

// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array(’(\n+)’,
‘(\r+)’,
‘(\t+)’,
‘(%0A+)’,
‘(%0D+)’,
‘(%08+)’,
‘(%09+)’
);
$inject = join(’|’, $injections);
$inject = “/$inject/i”;
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
};

if ($itemcount == 0)
{
header("Location: ".“error.php?msg=”.rawurlencode(“Voeg aub eerst evenementen toe voordat u uw informatieaanvraag afrondt.”));
$strHTML = “U heeft nog geen evenementen aangeklikt.”;
exit;
}

$errors = ‘’;
$firstname = ‘’;
$lastname = ‘’;
$straatnaam = ‘’;
$huisnummer = ‘’;
$postcode = ‘’;
$woonplaats = ‘’;
$land = ‘’;
$visitor_email = ‘’;
$telefoonnummer = ‘’;
$deelnemers = ‘’;
$optiedatum = ‘’;
$opmerkingen = ‘’;
$straatnaam_feestlocatie = ‘’;
$huisnummer_feestlocatie = ‘’;
$postcode_feestlocatie = ‘’;
$plaats_feestlocatie = ‘’;
$land_feestlocatie = ‘’;

$strHTML = “<div style=“overflow:auto; height=358px;”>”."\n";
$strHTML .= “<table border=“0” cellpadding=“3” cellspacing=“2” width=“100%”>”."\n";

for ($i=0; $i<$itemcount; $i++)
{
$strHTML .= “

”."\n";
$strHTML .= “<a href=’”.$cart[PRODUCTNAME][$i][‘savelink’]."’ class=‘bewaardeItems’>".$cart[PRODUCTNAME][$i][‘eventnaam’].""."\n";
$strHTML .= “”."\n";
}

$strHTML .= “”."\n";
$strHTML .= “”."\n";

if(isset($_POST[‘submit’]))
{

$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$straatnaam = $_POST['straatnaam'];
$huisnummer = $_POST['huisnummer'];
$postcode = $_POST['postcode'];
$woonplaats = $_POST['woonplaats'];
$land = $_POST['land'];
$visitor_email = $_POST['email'];
$telefoonnummer = $_POST['telefoonnummer'];
$deelnemers = $_POST['deelnemers'];
$optiedatum = $_POST['optiedatum'];
$opmerkingen = $_POST['opmerkingen'];
$straatnaam_feestlocatie = $_POST['straatnaam_feestlocatie'];
$huisnummer_feestlocatie = $_POST['huisnummer_feestlocatie'];
$postcode_feestlocatie = $_POST['postcode_feestlocatie'];
$plaats_feestlocatie = $_POST['plaats_feestlocatie'];
$land_feestlocatie = $_POST['land_feestlocatie'];
///------------Do Validations-------------
if(empty($lastname)||empty($visitor_email))
{
	$errors .= "\n Naam en email zijn verplicht. ";	
}
if(IsInjected($visitor_email))
{
	$errors .= "\n Ongeldige email!";
}
if(empty($_SESSION['6_letters_code'] ) ||
  strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
{
	$errors .= "\n De beveiligingscode komt niet overeen!";
}

if(empty($errors))
{
	if (!isset($visitor_email))

{
header("Location: ".“error.php?msg=”.rawurlencode(“We hebben uw gegevens niet ontvangen, probeert u het aub. nogmaals.”));
exit;
}

// create a unique order ID
$orderid = strtotime(“now”).$_SERVER[‘REMOTE_ADDR’];
$orderid = str_replace(".", “”, “$orderid”);

// create a timestamp
$timestamp = date(“Y-m-d H:i:s”);

// mail to customer
$subject = “Informatie aanvraag Entertain You events”;
$title = “Wij hebben uw aanvraag ontvangen, waarvoor hartelijk dank! Wij streven er naar om u binnen 2 werkdagen van antwoord te voorzien. Ondanks dat deze mail automatisch is opgesteld, kunt u eventuele vragen stellen door deze mail te beantwoorden.”;
SendEmail($visitor_email, $subject, $title, $orderid, $timestamp, true);

// mail to me
$subject = “Nieuwe informatie aanvraag”;
$title = “Dhr. / Mevr. “.$lastname.” heeft het contactformulier ingevuld. De volgende gegevens zijn daarbij verzonden:”;
SendEmail($LMEY_email, $subject, $title, $orderid, $timestamp, false);

header("Location: succes.php?msg=‘Succes!’ ");
}
}[/php]

Okay, I placed your code into my editor and reformatted it to be the way I layout code.
(Makes it easier for me that way.)

Right off the bat, I noticed some issues.

First, remove the semicolon on line 83. (Not needed)

Next, lines 85 to 90 do not make sense. If itemcount is zero you go to an error page. That is good.
But, any lines AFTER the header reidrect do not get executed. Lines 88-89 are not needed. I would jsut
replace lines 85 to 90 with this line:
[php]
if ($itemcount == 0) header("Location: ".“error.php?msg=”.rawurlencode(“Voeg aub eerst evenementen toe voordat u uw informatieaanvraag afrondt.”));
[/php]
(No need for brackets if just one command is executed…)

Line 162 checks for a visitor and moves to the error page if so. The exit on line 165 never executes, you
can delete that line.

Well, other than those minor problems, the rest looks correct. Fix those and let us know if all is well or if
you have errors. I think you are getting very close to finishing it… Good luck.

Some further info on IF’s and brackets. I thought I should explain more so you fully understand this.

IF’s are usually done in the format of:

if (condition) { one or more lines of code }

If you have only one line of code to execute, the brackets are optional.

You can use these in just about any format that makes it easy for YOU to read. So, there are some lines
in your validation area that only have one line of code. I did not mention removing the brackets for these
because some of your validation code have more than one line. So, it is easier to read leaving those in.

Just wanted to be clear on these. Let us know how it is working now…

Thanks for fixing the minor bugs. I really don’t understand why it’s just sending half of the data…

I’ll show you the email that I receive (the customer doesn’t receive anything, it does give an error on my server though).

This is the email. Values in green do work, the ones in red are missing.

Dhr. / Mevr. $lastname heeft het contactformulier ingevuld. De volgende gegevens zijn daarbij verzonden:

Aanvraagnummer: $orderid
Aanvraagdatum: $timestamp

Persoonlijke gegevens:
Voornaam: $firstname
Achternaam: $lastname
Email: $email
Adres: $straatnaam $huisnummer
Woonplaats: $woonplaats
Postcode: $postcode
Land: $land
Telefoonnummer: also doesn’t work

Adres feestlocatie:
Naam: also doesn’t work
Adres: also doesn’t work
Woonplaats: also doesn’t work
Postcode: also doesn’t work
Land: also doesn’t work

Overige info: also doesn’t work
Optie datum: also doesn’t work
Verwachte aantal deelnemers: also doesn’t work

Informatie-aanvraag over de volgende evenementen:

=======================================================
array of products from cart works just fine

Also, after changing the header it still doesn’t redirect. I really can’t find the problem. Why is the $lastname inside of the $title working while all other data inside of the function don’t? I’m guessing that’s also the problem of the mail-to-customer function. It reaches the function but can’t find any emailadres there, because these variables are all empty too…

Well, you get the $firstname from your field that get posted using this line:
$firstname=$_POST[“firstname”];
I have never really seen this type of line fail unless something is spelled wrong.
So, you should check your folrm and see if the input field for the first name is correct.
First, it must be spelled correctly, “firstname” and it must be the NAME of the field and not the ID of it.
So, the input field should be something like:
Sometimes people forget it is NAME and use ID instead.

You most likely spelled it differently. Check those out and let us know. (We can not see your form as you
did not post it.) Good luck.

That was also what I thought. I checked the input fields. Can’t find any problems either. This is the complete form:

[php]














Uw naam


Voornaam



Achternaam*


 
        </td>
        </tr>
        <tr>
        <td colspan="2">
        <font class="postcard_opening_02">
        Persoonlijke adresgegevens
        </font>
        </td>
        </tr>
        <tr>
        <td class="postcard_gegevens_01">
        Straatnaam
        </td>
        <td>
        <input type="text" name="straatnaam" class="postcard_gegevens_02" value='<?php echo htmlentities($straatnaam) ?>'>
        </td>
        </tr>
        <tr>
        <td class="postcard_gegevens_01">
        Huisnummer
        </td>
        <td>
        <input type="text" name="huisnummer" class="postcard_gegevens_02" value='<?php echo htmlentities($huisnummer) ?>'>
        </td>
        </tr>
        <tr>
        <td class="postcard_gegevens_01">
        Postcode
        </td>
        <td>
        <input type="text" name="postcode" class="postcard_gegevens_02" value='<?php echo htmlentities($postcode) ?>'>
        </td>
        </tr>
        <tr>
        <td class="postcard_gegevens_01">
        Woonplaats
        </td>
        <td>
        <input type="text" name="woonplaats" class="postcard_gegevens_02" value='<?php echo htmlentities($woonplaats) ?>'>
        </td>
        </tr>
        <tr>
        <td class="postcard_gegevens_01">
        Land
        </td>
        <td>
        <input type="text" name="land" class="postcard_gegevens_02" value='<?php echo htmlentities($land) ?>'>
        </td>
        </tr>
        <tr>
        <td colspan="2">&nbsp;
        
        </td>
        </tr>
        <tr>
        <td colspan="2">
        <font class="postcard_opening_02">
        Hoe kunnen we u bereiken?
        </font>
        </td>
        </tr>
        <tr>
        <td class="postcard_gegevens_01">
        E-mail*
        </td>
        <td>
        <input type="text" name="email" class="postcard_gegevens_02" value='<?php echo htmlentities($visitor_email) ?>'>
        </td>
        </tr>
        <tr>
        <td class="postcard_gegevens_01">
        Telefoonnummer
        </td>
        <td>
        <input type="text" name="telefoonnummer" class="postcard_gegevens_02" value='<?php echo htmlentities($telefoonnummer) ?>'>
        </td>
        </tr>
        <tr>
        <td colspan="2">&nbsp;
        
        </td>
        </tr>
        <tr>
        <td colspan="2">
        <font class="postcard_opening_02">
        Extra
        </font>
        </td>
        </tr>
        <tr>
        <td class="postcard_gegevens_01">
        Verwachte aantal deelnemers
        </td>
        <td>
        <input type="text" name="deelnemers" class="postcard_gegevens_02" value='<?php echo htmlentities($deelnemers) ?>'>
        </td>
        </tr>
        <tr>
        <td class="postcard_gegevens_01">
        Optie op datum
        </td>
        <td>
        <input type="text" name="optiedatum" class="postcard_gegevens_02" value='<?php echo htmlentities($optiedatum) ?>'>
        </td>
        </tr>
        <tr>
        <td class="postcard_gegevens_01">
        Opmerkingen
        </td>
        <td>
        <input type="text" name="opmerkingen" class="postcard_gegevens_02" value='<?php echo htmlentities($opmerkingen) ?>'>
        </td>
        </tr>
        </table>
        
        </td>
        <td class="postcard_gegevens" valign="top">
        
        <table width="100%">
        <td colspan="2">
        <font class="postcard_opening_02">
        Gegevens feestlocatie
        </font>
        </td>
        <tr>
        <td class="postcard_gegevens_03" colspan="2">
        <div class="postcard_postzegelBlokkade">
        Indien u dat wenst, kunt u ook meteen het adres van uw feestlocatie invoeren. Deze gegevens worden dan bewaard bij uw persoonlijke gegevens. Hier voert u dus niet uw eigen adres in, maar het adres waar uw evenement plaats zal vinden. Mocht dit hetzelfde adres zijn als uw persoonlijk adres, of wenst u deze gegevens niet in te vullen, kunt u de velden gewoon leeg laten.
        </div>
        </td>
        </tr>
        <tr>
        <td colspan="2">&nbsp;
        
        </td>
        </tr>
        <tr>
        <td colspan="2">
        <font class="postcard_opening_02">
        Adresgegevens feestlocatie
        </font>
        </td>
        </tr>
        <tr>
        <td class="postcard_gegevens_01">
        Straatnaam
        </td>
        <td>
        <input type="text" name="straatnaam_feestlocatie" class="postcard_gegevens_02" value='<?php echo htmlentities($straatnaam_feestlocatie) ?>'>
        </td>
        </tr>
        <tr>
        <td class="postcard_gegevens_01">
        Huisnummer
        </td>
        <td>
        <input type="text" name="huisnummer_feestlocatie" class="postcard_gegevens_02" value='<?php echo htmlentities($huisnummer_feestlocatie) ?>'>
        </td>
        </tr>
        <tr>
        <td class="postcard_gegevens_01">
        Postcode
        </td>
        <td>
        <input type="text" name="postcode_feestlocatie" class="postcard_gegevens_02" value='<?php echo htmlentities($postcode_feestlocatie) ?>'>
        </td>
        </tr>
        <tr>
        <td class="postcard_gegevens_01">
        Plaats
        </td>
        <td>
        <input type="text" name="plaats_feestlocatie" class="postcard_gegevens_02" value='<?php echo htmlentities($plaats_feestlocatie) ?>'>
        </td>
        </tr>
        <tr>
        <td class="postcard_gegevens_01">
        Land
        </td>
        <td>
        <input type="text" name="land_feestlocatie" class="postcard_gegevens_02" value='<?php echo htmlentities($land_feestlocatie) ?>'>
        </td>
        </tr>
        <tr>
        <td colspan="2">&nbsp;
        
        </td>
        </tr>
        <tr>
        <td class="postcard_gegevens_01">
		<img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' >
        </td>
        <td>
		<input id="6_letters_code" name="6_letters_code" type="text" class="postcard_gegevens_02">
        </td>
        </tr>
        <tr>
        <td class="postcard_gegevens_01">
		<font class="eventOmschrijving">Afbeeding onleesbaar? Klik <a href='javascript: refreshCaptcha();'>hier</a> om te vernieuwen.</font>
        </td>
        <td>
		<input type="submit" value="Verzenden" name='submit'>
        </td>
        </tr>
        </table>
        </form>[/php]

;D found a way to solve a very big part of the problem:

I’ve added $firstname to these lines:

[php]function SendEmail($mailto, $subject, $title, $orderid, $timestamp, $maskcardno, $firstname)[/php]

[php]SendEmail($visitor_email, $subject, $title, $orderid, $timestamp, true, $firstname);[/php]

[php]SendEmail($visitor_email, $subject, $title, $orderid, $timestamp, false, $firstname);[/php]

and now $firstname is sent with the email. So my guess is that I have to add all variables to the SendEmail call and function in order to have it sent with the mail. That solved the biggest part of my question.

Still leaves me with one thing: the redirect. Why am I not being redirected to the succes page as soon as the email is sent?

Oh, my gosh! I am very sorry. I didn’t notice your variable’s scope. SO, to explain this.

Variables used in your PHP file are not passed to functions. They can be if you decalre them as “global”
ones. So, if you define a variable like $x=99; then that is a valid variable that can be used throughout
your page but, not inside of functions. That is because you can declare a new version of the $x variable
for use only inside that function.

Here is a link to exlplain it further… http://www.w3schools.com/php/php_variables.asp

So, to fix this, you have two choices. You can either move the code where you acquire the posted values
from the form ( $firstname=$_POST[“firstname”]; ) up to inside the funciton. Or, make the variables into
“GLOBAL” versions. This would be done by using the global array inside the function. So, to do that, in
the function, when you use $firstname, instead use $GLOBALS[‘firstname’] .

While discussing this, you should also remember that when you call a function, all ( ALL ) of it’s “LOCAL”
variables which means all variables you create inside the function, are all deleted once the function is
done. There are ways to pass them back, either by returning them or by making them global.

Very sorry that I did not catch that sooner. Sometimes a programmer doesn’t see the tree for the forest.
I once spent two days missing a semi-colon that was a colon. Hope all this helps…

Unfortunately this happens to me too, way too often ::slight_smile: Anyway, I’m glad that I found the problem and I’m very thankfull for the time you took to help me. I am still wonderring thought if you know the problem in the redirect part? So how can I send the customer to the succes.php page after both emails are sent?

nevermind :wink: I changed all the variables to this GLOBAL function and it works just fine now, also the redirect. One part is still not functioning: the customer doesn’t receive an email. I didn’t take a close look on it yet but maybe you can help me. I receive an email (so $LMEY_email is working), the customer doesn’t ($visitor_email)

if I change the line

[php]SendEmail($visitor_email, $subject, $title, $orderid, $timestamp, true);[/php]

to

[php]SendEmail($LMEY_email, $subject, $title, $orderid, $timestamp, true);[/php]

I receive both emails. So the problems is that $visitor_email is empty at the moment the SendEmail needs to be executed. At the beginning, on top of the page I define the $LMEY_email already, because this is a fixed emailaddress. But the customer’s emailaddress is different all the time, so I can’t define this on top of the page. That’s my guess of what the problem is. How can I get the right data binded to the $visitor_email?

Well, the code you posted for the meail section should work…
[php]
// mail to customer
$subject = “Informatie aanvraag Entertain You events”;
$title = “Wij hebben uw aanvraag ontvangen, waarvoor hartelijk dank! Wij streven er naar om u binnen 2 werkdagen van antwoord te voorzien. Ondanks dat deze mail automatisch is opgesteld, kunt u eventuele vragen stellen door deze mail te beantwoorden.”;
SendEmail($visitor_email, $subject, $title, $orderid, $timestamp, true);

		// mail to me
		$subject = "Nieuwe informatie aanvraag";
		$title = "Dhr. / Mevr. ".$lastname." heeft het contactformulier ingevuld. De volgende gegevens zijn daarbij verzonden:";
		SendEmail($LMEY_email, $subject, $title, $orderid, $timestamp, false);

	 	header("Location: succes.php?msg='Succes!' ");

[/php]
Make sure that you change the variables in the function to use the $GLOBALS[] version.
And, make sure that you have the succes.php file in the same folder as this program.
Also, make sure that it is spelled exactly correct. Capitals are very important in HEADER() functions.
Success.php is NOT the same as succes.php or success.php… Finally, make sure that the succes.php
does not have an error in it. ( If you do not have any security in place on that page, just go to the site
and view the succes.php page manually to see if it shows up! )
If you get your email, then, it should redirect to the page. Good luck, let us know…

redirect works, customer email doesn’t.

This is what I have right now:

the php part:
[php]
session_start();

ini_set(‘display_errors’, 1);
error_reporting(E_ALL);

define(“PRODUCTNAME”, 1);
$LMEY_email =‘[email protected]’;

$cart = isset($_SESSION[‘cart’]) ? $_SESSION[‘cart’] : ‘’;
$itemcount = isset($_SESSION[‘itemcount’]) ? $_SESSION[‘itemcount’] : 0;

function SendEmail($mailto, $subject, $title, $orderid, $timestamp, $maskcardno)
{
$email_headers = “From: Entertain You Events”."\r\n";
$email_headers .= “Reply-To: “.$mailto.”\r\n”;
$email_headers .= “MIME-Version: 1.0”."\r\n";
$email_headers .= “Content-Type: text/plain; charset=utf-8”."\r\n";

$message = $title."\r\n"."\r\n";
$message .= “Aanvraagnummer: LMEY”.$GLOBALS[‘orderid’]."\r\n";
$message .= “Aanvraagdatum: “.$GLOBALS[‘timestamp’].”\r\n”."\r\n";

$message .= “Persoonlijke gegevens: \r\n”;
$message .= “Voornaam: “.$GLOBALS[‘firstname’].”\r\n”;
$message .= “Achternaam: “.$GLOBALS[‘lastname’].”\r\n”;
$message .= “Email: “.$GLOBALS[‘visitor_email’].”\r\n”;
$message .= “Adres: “.$GLOBALS[‘straatnaam’].” “.$GLOBALS[‘huisnummer’].”\r\n”;
$message .= “Woonplaats: “.$GLOBALS[‘woonplaats’].”\r\n”;
$message .= “Postcode: “.$GLOBALS[‘postcode’].”\r\n”;
$message .= “Land: “.$GLOBALS[‘land’].”\r\n”;
$message .= “Telefoonnummer: “.$GLOBALS[‘telefoonnummer’].”\r\n”."\r\n";

$message .= “Adres feestlocatie:”."\r\n";
$message .= “Adres: “.$GLOBALS[‘straatnaam_feestlocatie’].” “.$GLOBALS[‘huisnummer_feestlocatie’].”\r\n”;
$message .= “Postcode: “.$GLOBALS[‘postcode_feestlocatie’].”\r\n”;
$message .= “Plaats: “.$GLOBALS[‘plaats_feestlocatie’].”\r\n”;
$message .= “Land: “.$GLOBALS[‘land_feestlocatie’].”\r\n”."\r\n";

$message .= “Overige info:”."\r\n";
$message .= “Optie datum: “.$GLOBALS[‘optiedatum’].”\r\n”;
$message .= “Verwachte aantal deelnemers: “.$GLOBALS[‘deelnemers’].”\r\n”."\r\n";

$message .= “Informatie-aanvraag over de volgende evenementen:”."\r\n"."\r\n";
$message .= “=======================================================”."\r\n";

$itemcount = $_SESSION[‘itemcount’];
$cart = $_SESSION[‘cart’];

for ($i=0; $i<$itemcount; $i++)
{
$message .= $cart[PRODUCTNAME][$i][‘eventnaam’]."\t";
$message .= “\r\n”;
}

$message .= “=======================================================”."\r\n";
$message .= “\r\n”."\r\n";

mail($mailto, $subject, stripslashes($message), $email_headers);

}

function IsInjected($str)
{
$injections = array(’(\n+)’,
‘(\r+)’,
‘(\t+)’,
‘(%0A+)’,
‘(%0D+)’,
‘(%08+)’,
‘(%09+)’
);
$inject = join(’|’, $injections);
$inject = “/$inject/i”;
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}

$errors = ‘’;
$firstname = ‘’;
$lastname = ‘’;
$straatnaam = ‘’;
$huisnummer = ‘’;
$postcode = ‘’;
$woonplaats = ‘’;
$land = ‘’;
$visitor_email = ‘’;
$telefoonnummer = ‘’;
$deelnemers = ‘’;
$optiedatum = ‘’;
$opmerkingen = ‘’;
$straatnaam_feestlocatie = ‘’;
$huisnummer_feestlocatie = ‘’;
$postcode_feestlocatie = ‘’;
$plaats_feestlocatie = ‘’;
$land_feestlocatie = ‘’;

if ($itemcount == 0)
{
header("Location: ".“error.php?msg=”.rawurlencode(“Voeg aub eerst evenementen toe voordat u uw informatieaanvraag afrondt.”));
}

$strHTML = “<div style=“overflow:auto; height=358px;”>”."\n";
$strHTML .= “<table border=“0” cellpadding=“3” cellspacing=“2” width=“100%”>”."\n";

for ($i=0; $i<$itemcount; $i++)
{
$strHTML .= “

”."\n";
$strHTML .= “<a href=’”.$cart[PRODUCTNAME][$i][‘savelink’]."’ class=‘bewaardeItems’>".$cart[PRODUCTNAME][$i][‘eventnaam’].""."\n";
$strHTML .= “”."\n";
}

$strHTML .= “”."\n";
$strHTML .= “”."\n";

if(isset($_POST[‘submit’]))
{

$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$straatnaam = $_POST['straatnaam'];
$huisnummer = $_POST['huisnummer'];
$postcode = $_POST['postcode'];
$woonplaats = $_POST['woonplaats'];
$land = $_POST['land'];
$visitor_email = $_POST['email'];
$telefoonnummer = $_POST['telefoonnummer'];
$deelnemers = $_POST['deelnemers'];
$optiedatum = $_POST['optiedatum'];
$opmerkingen = $_POST['opmerkingen'];
$straatnaam_feestlocatie = $_POST['straatnaam_feestlocatie'];
$huisnummer_feestlocatie = $_POST['huisnummer_feestlocatie'];
$postcode_feestlocatie = $_POST['postcode_feestlocatie'];
$plaats_feestlocatie = $_POST['plaats_feestlocatie'];
$land_feestlocatie = $_POST['land_feestlocatie'];
///------------Do Validations-------------
if(empty($lastname)||empty($visitor_email))
{
	$errors .= "\n Naam en email zijn verplicht. ";	
}
if(IsInjected($visitor_email))
{
	$errors .= "\n Ongeldige email!";
}
if(empty($_SESSION['6_letters_code'] ) ||
  strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
{
	$errors .= "\n De beveiligingscode komt niet overeen!";
}

if(empty($errors))
{
	if (!isset($visitor_email))

{
header("Location: ".“error.php?msg=”.rawurlencode(“We hebben uw gegevens niet ontvangen, probeert u het aub. nogmaals.”));
}

$orderid = strtotime(“now”).$_SERVER[‘REMOTE_ADDR’];
$orderid = str_replace(".", “”, “$orderid”);

$timestamp = date(“Y-m-d H:i:s”);

// mail to customer
$subject = “Informatie aanvraag Entertain You events”;
$title = “Wij hebben uw aanvraag ontvangen, waarvoor hartelijk dank! Wij streven er naar om u binnen 2 werkdagen van antwoord te voorzien. Ondanks dat deze mail automatisch is opgesteld, kunt u eventuele vragen stellen door deze mail te beantwoorden.”;
SendEmail($visitor_email, $subject, $title, $orderid, $timestamp, true);

// mail to me
$subject = “Nieuwe informatie aanvraag”;
$title = “Dhr. / Mevr. “.$lastname.” heeft het contactformulier ingevuld. De volgende gegevens zijn daarbij verzonden:”;
SendEmail($LMEY_email, $subject, $title, $orderid, $timestamp, false);

header("Location: verzonden_deleteSession.php ");
}
}
[/php]

the form part:

[php]

Uw naam
Voornaam
Achternaam*
 
          </td>
          </tr>
          <tr>
          <td colspan="2">
          <font class="postcard_opening_02">
          Persoonlijke adresgegevens
          </font>
          </td>
          </tr>
          <tr>
          <td class="postcard_gegevens_01">
          Straatnaam
          </td>
          <td>
          <input type="text" name="straatnaam" class="postcard_gegevens_02" value='<?php echo htmlentities($straatnaam) ?>'>
          </td>
          </tr>
          <tr>
          <td class="postcard_gegevens_01">
          Huisnummer
          </td>
          <td>
          <input type="text" name="huisnummer" class="postcard_gegevens_02" value='<?php echo htmlentities($huisnummer) ?>'>
          </td>
          </tr>
          <tr>
          <td class="postcard_gegevens_01">
          Postcode
          </td>
          <td>
          <input type="text" name="postcode" class="postcard_gegevens_02" value='<?php echo htmlentities($postcode) ?>'>
          </td>
          </tr>
          <tr>
          <td class="postcard_gegevens_01">
          Woonplaats
          </td>
          <td>
          <input type="text" name="woonplaats" class="postcard_gegevens_02" value='<?php echo htmlentities($woonplaats) ?>'>
          </td>
          </tr>
          <tr>
          <td class="postcard_gegevens_01">
          Land
          </td>
          <td>
          <input type="text" name="land" class="postcard_gegevens_02" value='<?php echo htmlentities($land) ?>'>
          </td>
          </tr>
          <tr>
          <td colspan="2">&nbsp;
          
          </td>
          </tr>
          <tr>
          <td colspan="2">
          <font class="postcard_opening_02">
          Hoe kunnen we u bereiken?
          </font>
          </td>
          </tr>
          <tr>
          <td class="postcard_gegevens_01">
          E-mail*
          </td>
          <td>
          <input type="text" name="email" class="postcard_gegevens_02" value='<?php echo htmlentities($visitor_email) ?>'>
          </td>
          </tr>
          <tr>
          <td class="postcard_gegevens_01">
          Telefoonnummer
          </td>
         <td>
         <input type="text" name="telefoonnummer" class="postcard_gegevens_02" value='<?php echo htmlentities($telefoonnummer) ?>'>
         </td>
         </tr>
         <tr>
         <td colspan="2">&nbsp;
         
         </td>
         </tr>
         <tr>
         <td colspan="2">
         <font class="postcard_opening_02">
         Extra
         </font>
         </td>
         </tr>
         <tr>
         <td class="postcard_gegevens_01">
         Verwachte aantal deelnemers
         </td>
         <td>
         <input type="text" name="deelnemers" class="postcard_gegevens_02" value='<?php echo htmlentities($deelnemers) ?>'>
         </td>
         </tr>
         <tr>
         <td class="postcard_gegevens_01">
         Optie op datum
         </td>
         <td>
         <input type="text" name="optiedatum" class="postcard_gegevens_02" value='<?php echo htmlentities($optiedatum) ?>'>
         </td>
         </tr>
         <tr>
         <td class="postcard_gegevens_01">
         Opmerkingen
         </td>
         <td>
         <input type="text" name="opmerkingen" class="postcard_gegevens_02" value='<?php echo htmlentities($opmerkingen) ?>'>
         </td>
         </tr>
         </table>
         
         </td>
         <td class="postcard_gegevens" valign="top">
         
         <table width="100%">
         <td colspan="2">
         <font class="postcard_opening_02">
         Gegevens feestlocatie
         </font>
         </td>
         <tr>
         <td class="postcard_gegevens_03" colspan="2">
         <div class="postcard_postzegelBlokkade">
         Indien u dat wenst, kunt u ook meteen het adres van uw feestlocatie invoeren. Deze gegevens worden dan bewaard bij uw persoonlijke gegevens. Hier voert u dus niet uw eigen adres in, maar het adres waar uw evenement plaats zal vinden. Mocht dit hetzelfde adres zijn als uw persoonlijk adres, of wenst u deze gegevens niet in te vullen, kunt u de velden gewoon leeg laten.
         </div>
         </td>
         </tr>
         <tr>
         <td colspan="2">&nbsp;
         
         </td>
         </tr>
         <tr>
         <td colspan="2">
         <font class="postcard_opening_02">
         Adresgegevens feestlocatie
         </font>
         </td>
         </tr>
         <tr>
         <td class="postcard_gegevens_01">
         Straatnaam
         </td>
         <td>
         <input type="text" name="straatnaam_feestlocatie" class="postcard_gegevens_02" value='<?php echo htmlentities($straatnaam_feestlocatie) ?>'>
         </td>
         </tr>
         <tr>
         <td class="postcard_gegevens_01">
         Huisnummer
         </td>
         <td>
         <input type="text" name="huisnummer_feestlocatie" class="postcard_gegevens_02" value='<?php echo htmlentities($huisnummer_feestlocatie) ?>'>
         </td>
         </tr>
         <tr>
         <td class="postcard_gegevens_01">
         Postcode
         </td>
         <td>
         <input type="text" name="postcode_feestlocatie" class="postcard_gegevens_02" value='<?php echo htmlentities($postcode_feestlocatie) ?>'>
         </td>
         </tr>
         <tr>
         <td class="postcard_gegevens_01">
         Plaats
         </td>
         <td>
         <input type="text" name="plaats_feestlocatie" class="postcard_gegevens_02" value='<?php echo htmlentities($plaats_feestlocatie) ?>'>
         </td>
         </tr>
         <tr>
         <td class="postcard_gegevens_01">
         Land
         </td>
         <td>
         <input type="text" name="land_feestlocatie" class="postcard_gegevens_02" value='<?php echo htmlentities($land_feestlocatie) ?>'>
         </td>
         </tr>
         <tr>
         <td colspan="2">&nbsp;
         
         </td>
         </tr>
         <tr>
         <td class="postcard_gegevens_01">
		<img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' >
         </td>
         <td>
		<input id="6_letters_code" name="6_letters_code" type="text" class="postcard_gegevens_02">
         </td>
         </tr>
         <tr>
         <td class="postcard_gegevens_01">
		<font class="eventOmschrijving">Afbeeding onleesbaar? Klik <a href='javascript: refreshCaptcha();'>hier</a> om te vernieuwen.</font>
         </td>
         <td>
		<input type="submit" value="Verzenden" name='submit'>
         </td>
         </tr>
         </table>
         </form>

[/php]

So the email is sent to me with all the variables in it. The customer doesn’t receive an email. So the $visitor_email stays empty, as I wrote in my previous message. Somehow this variable can’t be red. On my server mailaccount I do get an error mail (Mail Delivery System; Message could not be delivered. Please ensure the message is RFC 5322 compliant). This error mail does echo the mailaddress of where the email should have been send to, it just doesn’t deliver it at that specific mailaddress…

Sponsor our Newsletter | Privacy Policy | Terms of Service