Niet alle gegevens van het PHP script worden naar mijn email verzonden

Status
Niet open voor verdere reacties.

Spellmeista

Gebruiker
Lid geworden
23 feb 2009
Berichten
24
Beste mensen,
ik ben al aardig ver ;) en ik heb eindelijk na vijf dagen van zwoegen en vloeken :( een php script zover gekregen dat ik netjes een mailtje binnenkrijg! Applaus voor mezelf :D

Nu komt het volgende probleem. Alles werkt naar behoren echter de checkbox invoer krijg ik niet via de mail binnen en dit natuurlijk ook belangrijk om te weten of mensen in de toekomst op de hoogte gehouden willen worden over eventuele ontwikkelingen! Kan iemand even kijken naar dit php script en zeggen waarom hij de checkbox optie = ON niet stuurt naar het mailadres?
PHP:
<?php

/* All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. */
$email = 'mijnnaam@domein.nl';
$ophoogte = $HTTP_POST_VARS['ophoogte'];
$subject = 'mail afkomstig van [url]www.3volt.nl';[/url]
$message = $HTTP_POST_VARS['message'];
$uwemail = $HTTP_POST_VARS['uwemail'];

/* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */
if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
echo "<h4>Invalid email address</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
} elseif ($subject == "") {
echo "<h4>No subject</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
}

/* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */
elseif (mail($email,$subject, "Van: $uwemail",$message, $ophoogte)) {
echo "<h4>Dank u voor uw interesse in Revolt. Indien het een vraag betreft krijgt u zsm antwoord!</h4>";
} else {
echo "<h4>Can't send email to $email</h4>";
}
?>

--------------------------------------------------------------------------------------
$ophoogte is in dit geval de waarde van de checkbox
--------------------------------------------------------------------------------------
 
Laatst bewerkt door een moderator:
Ik weet niet welke versie van PHP je gebruikt, maar $_HTTP_POST_VARS is verouderd. Gebruik in plaats daarvan $_POST.

Dan doe je vervolgens:

PHP:
$ophoogte = (isset($_POST['ophoogte'])) ? 'ON' : 'OFF';
 
En dan pas je deze regel aan:
PHP:
elseif (mail($email,$subject, "Van: $uwemail",$message, $ophoogte)) {
zodat $ophoogte niet meer voor de headers staat.

Dus dat zal zoiets worden:
PHP:
elseif (mail($email,$subject, "Van: $uwemail",$message ."Ophoogte: ". $ophoogte)) {
 
En dan pas je deze regel aan:
PHP:
elseif (mail($email,$subject, "Van: $uwemail",$message, $ophoogte)) {
zodat $ophoogte niet meer voor de headers staat.

Dus dat zal zoiets worden:
PHP:
elseif (mail($email,$subject, "Van: $uwemail",$message ."Ophoogte: ". $ophoogte)) {

Scherp, dat was me niet opgevallen, maar volgens mij klopt ie zo nog niet.

PHP:
mail($email, $subject, $message . $ophoogte, "From: $uwemail")

lijkt mij beter
 
Nog scherper ;)
 
Of eigenlijk, aangezien er nu slechts ON/OFF achter het bericht komt te hangen:

PHP:
mail($email, $subject, $message . "\r\n Ophoogte: " . $ophoogte, "From: $uwemail")
 
Of eigenlijk, aangezien er nu slechts ON/OFF achter het bericht komt te hangen:

PHP:
mail($email, $subject, $message . "\r\n Ophoogte: " . $ophoogte, "From: $uwemail")
Hoi thx alvast voor jullie hulp. Ik krijg nu wel een parse error:

Parse error: syntax error, unexpected T_VARIABLE in /var/www/g39936/3volt.nl/HTML/contact/contact.php on line 13

$email = 'naam@domein.nl';
$ophoogte = (isset($_POST['ophoogte'])) ? 'ON' : 'OFF'
$subject = 'mail afkomstig van www.3volt.nl';
$message = (isset($_POST['message']));
$uwemail = (isset($_POST['uwemail']));

En nog een vraagje: waarvoor staat die laatste \r\n bij ophoogte?
 
Laatst bewerkt:
Euhm, even voor de duidelijkheid, je kunt geen BB code gebruiken binnen PHP tags. Dat zag ik in je eerste post ook.

"\r\n" betekent niets anders dan ga verder op een nieuwe regel.

Kun je vertellen wat de parse error precies is? Welke regel?

Je hebt trouwens geen ; achter die regel met $ophoogte, dat is je fout.
 
Laatst bewerkt:
Erik teneerste wat is een BB code?

ok thx voor dat \r\n gebeuren te vertellen

ok ik heb nu ; erachter en hij verzend het formulier netjes echter ik krijg nu geen uwemail in de mail die naar mijn email adres verstuurd wordt. En dat is ook wel weer jammer..

Ik heb nu:
PHP:
$email = 'lnaam@domein.nl';
$ophoogte = (isset($_POST['ophoogte'])) ? 'ON' : 'OFF';
$subject = 'mail afkomstig van www.3volt.nl';
$message = (isset($_POST['message']));
$uwemail = (isset($_POST['uwemail']));
en dit verder:
PHP:
elseif (mail($email, $subject, $message . "\r\n Ophoogte: " . $ophoogte, "Van:" . $uwemail)) {
heel bizar hij laat er steeds eentje weg als hij het mailtje verstuurd..
 
Laatst bewerkt door een moderator:
BB code is code die je op fora gebruikt, zoals: en [b]. Het staat volgens mij voor...e functie mag [B]niet[/B] veranderen naar Van
 
Het lijkt mij handiger om de mailfunctie alleen met variabelen te doen.

Probeer dit eens:
PHP:
<?php
if($_SERVER['REQUEST_METHOD'] == "POST") {
  /* All form fields are automatically passed to the PHP script through the array $_POST. */
  $ophoogte = isset($_POST['ophoogte']) ? 'Ja' : 'Nee';

  $mailTo = 'mijnnaam@domein.nl';
  $mailSubject = 'mail afkomstig van www.3volt.nl';

  $mailMessage = 'Van: '. $_POST['uwemail'] ."\r\n";
  $mailMessage .= 'Bericht: '. $_POST['message'] ."\r\n";
  $mailMessage .= 'Houdt mij op de hoogte: '. $ophoogte;

  /* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */
  if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
    echo "<h4>Invalid email address</h4>";
    echo "<a href='javascript:history.back(1);'>Back</a>";
  } elseif ($subject == "") {
    echo "<h4>No subject</h4>";
    echo "<a href='javascript:history.back(1);'>Back</a>";
  }
  /* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */
  elseif (mail($mailTo,$mailSubject, $mailMessage)) {
    echo "<h4>Dank u voor uw interesse in Revolt. Indien het een vraag betreft krijgt u zsm antwoord!</h4>";
  } else {
    echo "<h4>Can't send email to $_POST['uwemail']</h4>";
  }
}
?>
 
Het lijkt mij handiger om de mailfunctie alleen met variabelen te doen.

Probeer dit eens:
{code}
Dit ga ik zo proberen..jah sorry hoor dat ik jullie hiermee opzadel, maar kom volgens mij wel steeds een stukje verder!
 
Laatst bewerkt door een moderator:
Dit ga ik zo proberen..jah sorry hoor dat ik jullie hiermee opzadel, maar kom volgens mij wel steeds een stukje verder!

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/g39936/3volt.nl/HTML/contact/contact2.php on line 25 Dit krijg ik in het laatste geval waarbij regel 25=

echo "<h4>Can't send email to $_POST['uwemail']</h4>";

Deze zin kan eigenlijk net zo goed weg volgens mij omdat ik het toch op laat sturen naar een geldig mailadres! Dat doe ik hier namelijk al:
$mailTo = 'mijnnaam@domein.nl';

Net zoals dit stuk:

/* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */
if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
echo "<h4>Invalid email address</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
} elseif ($subject == "") {
echo "<h4>No subject</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";

Ik definiër mailto namelijk al dmv mijn eigen email adres
 
Laatst bewerkt:
De controles zijn wel handig, ze staan alleen op de verkeerde variabelen.

Tevens had ik een foutje aan het eind :)
Dan wordt het zo:
PHP:
<?php 
if($_SERVER['REQUEST_METHOD'] == "POST") { 
  /* All form fields are automatically passed to the PHP script through the array $_POST. */ 
  $ophoogte = isset($_POST['ophoogte']) ? 'Ja' : 'Nee'; 

  $mailTo = 'mijnnaam@domein.nl'; 
  $mailSubject = 'mail afkomstig van www.3volt.nl'; 

  $mailMessage = 'Van: '. $_POST['uwemail'] ."\r\n"; 
  $mailMessage .= 'Bericht: '. $_POST['message'] ."\r\n"; 
  $mailMessage .= 'Houdt mij op de hoogte: '. $ophoogte; 

  /* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */ 
  if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $_POST['uwemail'])) { 
    echo "<h4>Invalid email address</h4>"; 
    echo "<a href='javascript:history.back(1);'>Back</a>"; 
  } elseif ($_POST['message'] == "") { 
    echo "<h4>No message</h4>"; 
    echo "<a href='javascript:history.back(1);'>Back</a>"; 
  } 
  /* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */ 
  elseif (mail($mailTo,$mailSubject, $mailMessage)) { 
    echo "<h4>Dank u voor uw interesse in Revolt. Indien het een vraag betreft krijgt u zsm antwoord!</h4>"; 
  } else { 
    echo "<h4>Can't send email to ". $_POST['uwemail'] ."</h4>"; 
  } 
} 
?>
 
De controles zijn wel handig, ze staan alleen op de verkeerde variabelen.

Tevens had ik een foutje aan het eind :)
Dan wordt het zo:
PHP:
<?php 
if($_SERVER['REQUEST_METHOD'] == "POST") { 
  /* All form fields are automatically passed to the PHP script through the array $_POST. */ 
  $ophoogte = isset($_POST['ophoogte']) ? 'Ja' : 'Nee'; 

  $mailTo = 'mijnnaam@domein.nl'; 
  $mailSubject = 'mail afkomstig van www.3volt.nl'; 

  $mailMessage = 'Van: '. $_POST['uwemail'] ."\r\n"; 
  $mailMessage .= 'Bericht: '. $_POST['message'] ."\r\n"; 
  $mailMessage .= 'Houdt mij op de hoogte: '. $ophoogte; 

  /* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */ 
  if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $_POST['uwemail'])) { 
    echo "<h4>Invalid email address</h4>"; 
    echo "<a href='javascript:history.back(1);'>Back</a>"; 
  } elseif ($_POST['message'] == "") { 
    echo "<h4>No message</h4>"; 
    echo "<a href='javascript:history.back(1);'>Back</a>"; 
  } 
  /* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */ 
  elseif (mail($mailTo,$mailSubject, $mailMessage)) { 
    echo "<h4>Dank u voor uw interesse in Revolt. Indien het een vraag betreft krijgt u zsm antwoord!</h4>"; 
  } else { 
    echo "<h4>Can't send email to ". $_POST['uwemail'] ."</h4>"; 
  } 
} 
?>

Antwoord:
Invalid email address

Back
 
Kan zijn dat de expressie niet goed is voor preg_match.

Probeer het zo eens:
PHP:
<?php  
if($_SERVER['REQUEST_METHOD'] == "POST") {  
  /* All form fields are automatically passed to the PHP script through the array $_POST. */  
  $ophoogte = isset($_POST['ophoogte']) ? 'Ja' : 'Nee';  

  $mailTo = 'mijnnaam@domein.nl';  
  $mailSubject = 'mail afkomstig van www.3volt.nl';  

  $mailMessage = 'Van: '. $_POST['uwemail'] ."\r\n";  
  $mailMessage .= 'Bericht: '. $_POST['message'] ."\r\n";  
  $mailMessage .= 'Houdt mij op de hoogte: '. $ophoogte;  

  /* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */  
  if (!preg_match(
"/^[A-Z0-9._%-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z]{2,6}$/i", $_POST['uwemail'])) {  
    echo "<h4>Invalid email address</h4>";  
    echo "<a href='javascript:history.back(1);'>Back</a>";  
  } elseif ($_POST['message'] == "") {  
    echo "<h4>No message</h4>";  
    echo "<a href='javascript:history.back(1);'>Back</a>";  
  }  
  /* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */  
  elseif (mail($mailTo,$mailSubject, $mailMessage)) {  
    echo "<h4>Dank u voor uw interesse in Revolt. Indien het een vraag betreft krijgt u zsm antwoord!</h4>";  
  } else {  
    echo "<h4>Can't send email to ". $_POST['uwemail'] ."</h4>";  
  }  
}  
?>
en uiteraard zorgen dat je een geldig adres invoert ;)
 
Godzijdank: dit werkte uiteindelijk:
PHP:
<?php 
if($_SERVER['REQUEST_METHOD'] == "POST") { 
  /* All form fields are automatically passed to the PHP script through the array $_POST. */ 
  $ophoogte = isset($_POST['ophoogte']) ? 'Ja' : 'Nee'; 

  $mailTo = 'naam@domein.nl'; 
  $mailSubject = 'mail afkomstig van www.3volt.nl';

  $mailMessage = 'Van: '. $_POST['uwemail'] ."\r\n"; 
  $mailMessage .= 'Bericht: '. $_POST['message'] ."\r\n"; 
  $mailMessage .= 'Houdt mij op de hoogte: '. $ophoogte; 

  /* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */ 
  if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $mailTo)) { 
    echo "<h4>Invalid email address</h4>"; 
    echo "<a href='javascript:history.back(1);'>Back</a>"; 
  } elseif ($mailSubject == "") { 
    echo "<h4>No subject</h4>"; 
    echo "<a href='javascript:history.back(1);'>Back</a>"; 
  } 
  /* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */ 
  elseif (mail($mailTo,$mailSubject,$mailMessage)) { 
    echo "<h4>Dank u voor uw interesse in Revolt. Indien het een vraag betreft krijgt u zsm antwoord!</h4>"; 
  } else { 
     echo "<h4>Can't send email to ". $_POST['uwemail'] ."</h4>";
  } 
} 
?>
:D

Mag ik jullie hartelijk bedanken voor de moeite!
 
Laatst bewerkt door een moderator:
Wazigste code van Nederland

Ziet u hier de wazigste PHP code van Nederland!!! :shocked:
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan