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]