php code that mails.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kheiremans
Forum Newbie
Posts: 3
Joined: Wed Mar 12, 2008 11:02 am

php code that mails.

Post by kheiremans »

Everah | Please use the appropriate bbCode tags when posting code in the forums. You can use either [code], [{lang}] or [syntax="{lang}"] where {lang} is the name of the language you want to highlight as. Thank you.

i've written a normal form and i want the info emailed to me.

i read some tutorials and wrote this.

when i run this and click on submit the page refreshes but i don't get the emails

Code: Select all

<?php
 
   if ($_SERVER['REQUEST_METHOD'] != 'POST'){
      $me = $_SERVER['PHP_SELF'];}
 
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
 
$error = '';
$water = '';
$swater = '';
$coffee = '';
$comment = '';
 
 
//if(empty($_POST['naam']))
    //$error .= "U heeft geen <strong>naam</strong> ingevuld.<br />\n";
//if(!empty($_POST['naam']) and strlen($_POST['naam']) < 3)
    //$error .= "U heeft een te korte <strong>naam</strong> ingevuld.<br />\n";
//if(empty($_POST['email']))
    //$error .= "U heeft geen <strong>emailadres</strong> ingevuld.<br />\n";
//if(!empty($_POST['email']) and !preg_match('/^[A-Za-z0-9._-]+@[A-Za-z0-9._-]+\.[A-Za-z]{2,6}$/', $_POST['email']))
    //$error .= "U heeft een ongeldig <strong>emailadres</strong> ingevuld.<br />\n";
//if(empty($_POST['onderwerp']))
    //$error .= "U heeft geen <strong>onderwerp</strong> ingevuld.<br />\n";
//if(!empty($_POST['onderwerp']) and strlen($_POST['onderwerp']) < 3)
    //$error .= "U heeft een te kort <strong>onderwerp</strong> ingevuld.<br />\n";
//if(empty($_POST['bericht']))
    //$error .= "U heeft geen <strong>bericht</strong> ingevuld.<br />\n";
if(!empty($_POST['numberOfWater']))
    $water = $_POST['numberOfWater'];
if(!empty($_POST['numberOfSparklingWater']))
    $swater = $_POST['numberOfSparklingWater'];
if(!empty($_POST['numberOfCoffee']))
    $coffee = $_POST['numberOfCoffee'];
if(!empty($_POST['selectCom']))
    $comment = $_POST['selectCom'];
 
if( $error )
{
    echo "<h3 style=\"color: #f00;\">Fout</h3>\n";
    echo "<p>" . $error . "</p>";
 
    }
 
    else
 
    {
 
 
    $bericht = "=============================
    BeginDatum: " . $_POST['selectDate'] . "
    BeginTijd: " . $_POST['selectBeginHour'] . "
    EindDatum: " . $_POST['selectEndDate'] . "
    EindTijd: " . $_POST['selectEndHour'] . "
    Onderwerp: " . $_POST['selectSubject'] . "
    Afzender: " . $_POST['selectAskingPerson'] . "
    EmailadresExtensie: " . $_POST['selectAskingPersonMailExt'] . "
    Tel: " . $_POST['selectAskingPersonTel'] . "
    AantalPersonen: " . $_POST['selectSubject'] . "
    Beamer: " . $_POST['rd'] . "
    AantalWater: " . $water . "
    AantalBruisWater: " . $swater . "
    AantalKoffie: " . $coffee . "
 
 
    Commentaar:
    -------------------------------------------
    " . $comment . "
    -------------------------------------------
    =============================";
 
    if (mail("kheiremans@yahoo.com",$_POST['selectSubject'],$bericht))
 
    {
 
    echo "<p>Uw reservatie is succesvol verzonden, bedankt!</p>\n";
    echo "<p>Votre reservation est transmis avec succes, merci!</p>\n";
 
    }
 
    else
 
    {
 
    echo "<h3 style=\"color: #f00;\">Fout/Erreur</h3>\n";
    echo "<p>De aanvraag kon niet verzonden worden, email mij direct via kheiremans@yahoo.com</p>\n";
    echo "<p>Votre reservation n'est pas transmis , envoyez-moi directement via kheiremans@yahoo.com</p>\n";
    }
    }
    }
 
    //if(  (!empty($error)) or $_SERVER['REQUEST_METHOD'] != "POST" )
 
    //{
 
 
 
    //$naam = isset($_POST['naam']) ? $_POST['naam'] : '';
    //$email = isset($_POST['email']) ? $_POST['email'] : '';
    //$onderwerp = isset($_POST['onderwerp']) ? $_POST['onderwerp'] : '';
    //$bericht = isset($_POST['bericht']) ? $_POST['bericht'] : '';
 
    ?>
Everah | Please use the appropriate bbCode tags when posting code in the forums. You can use either [code], [{lang}] or [syntax="{lang}"] where {lang} is the name of the language you want to highlight as. Thank you.
Last edited by RobertGonzalez on Wed Mar 12, 2008 11:19 am, edited 1 time in total.
Reason: Added bbCode tags note
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: php code that mails.

Post by andym01480 »

Run a test script to check your php config is okay

<?php
mail("kheiremans@yahoo.com","Test Email","Hello") or die("Oh dear");
?>
kheiremans
Forum Newbie
Posts: 3
Joined: Wed Mar 12, 2008 11:02 am

Re: php code that mails.

Post by kheiremans »

thanks alot i got this

Code: Select all

Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\Documents and Settings\Hoeremans\Bureaublad\apache-tomcat-5.5.17\webapps\phptest\test2.php on line 2
Oh dear

so i prolly need to modify my php.ini

edit 1:
i filled in smtp port and from and i don't get the errors anymore but the mail still doesn't send

edit 2:

the test works but the full script doesn't(but it doesn't generate errors)
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: php code that mails.

Post by andym01480 »

I'd add some diagnostics for now, to see what is going on

Code: Select all

error_reporting(E_ALL);
at the start of the script to throw up any errors.
so line 8

Code: Select all

echo "Processing";
- so you know the form was posted
line 72

Code: Select all

echo $bericht.'<br/>';
- just to check the message is okay
add a line at 72

Code: Select all

echo $_POST['selectSubject'].'<br/>';
- to check the subject

See what that throws up!
kheiremans
Forum Newbie
Posts: 3
Joined: Wed Mar 12, 2008 11:02 am

Re: php code that mails.

Post by kheiremans »

i've found it.

i missed ; after the mail function

thanks for the help
Post Reply