Php.in file

Ok, will try one simple form, maybe that will clear things out.

As I understand- you’re saying that PHP should check form fields not only if they are blank, but also check a format entered (for example email field should be ‘myemail@domain.com’)? Does PHP use RegEx?

Exactly! Fall back to Regex if you really have to.

PHP has evolved to hide many regexes behind the Filter classes I mentioned before. See :

http://www.php.net/manual/en/filter.filters.validate.php - validate email - yes/no
http://www.php.net/manual/en/filter.filters.sanitize.php - sanitize email - clean up and carry on

Thanks a lot! That is cool :slight_smile:

Will be back later with results and more questions :wink:

Hi
I managed to validate my form with jQuery, form sends email, but when clicked on ‘Send’- it opens another page, where my mail() is. I would like it not to be directed to .php file, how can I do that?

Once the email has been successfully sent, use PHP to redirect the user to a destination of your choice, does not have to be a PHP file…


if ($mailsent === true){

header("Location: /thankyou.htm");
exit();  // important!
}

Could even be to a PHP page with a flag that shows different messages:


{
header("Location: /thankyou.php?msg=23");
exit(); // !
}

thankyou.php


<?php

$wily_coyote_messages = array(
0=>"Funny? That should not happen ...",
1=>"Welcome, now please proceed under this huge rock.",
...
23="Your email is sent! Thanks for your interest in Acme Rocket Skates",
);

if( isset($_GET['msg'])){
echo "<p>" . $wily_coyote_messages [(int)$_GET['msg']] . "</p>";
}

Hey,

This is how my code looks like in send.php page, but it doesn’t work. Any ideas why? :slight_smile:

<?php
//start building the mail string
$msg .= "Name: “.$_POST[“name”].”
";
$msg .= "E-Mail: “.$_POST[“emailaddress”].”
";
$msg .= "Tel No: “.$_POST[“telNr”].”
";
$msg .= "Message: “.$_POST[“limitedtextarea”].”
";

//set up the mail
$recipient = “email@email.co.uk”;
$subject = “Subject”;
$mailheaders = "Mailheaders<email@email.com>
";
$mailheaders .= "Reply-To: ".$_POST[“email”];
//send the mail
mail($recipient, $subject, $msg, $mailheaders);

if ($mailsent === true){

header(“Location: /index.html”);
exit(); // important!
}
?>

“Doesn’t work” is not very descriptive.

What does not work? What error messages are you getting? What debugging have you done to narrow down which part does not work?

ps $msg should be initialized before you concatenate stuff to it, maybe you do this higher up and have not shown us? Else:


$msg = "Name: ".$_POST["name"]."\
";  // <-rm the dot and initialise the variable
$msg .= "E-Mail: ".$_POST["emailaddress"]."\
";
$msg .= "Tel No: ".$_POST["telNr"]."\
";
$msg .= "Message: ".$_POST["limitedtextarea"]."\
";

pps get used to wrapping PHP code samples with [php ]

 tags, makes it easier for anyone else to read.

By ‘it doesn’t work’ I meant that id does not redirect to another page once the form is submitted.

I realised, that it might be a wrong code. My form is on .html page, I want it to be send in the background (if it validates) and then thankyou.html to be displayed.

Sorry…

“PHP is a powerful tool for making dynamic and interactive Web pages.” As it says on W3C Schools :slight_smile:

I said right at beginning I am new to PHP, sorry…


mail($recipient, $subject, $msg, $mailheaders);

if ($mailsent === true){

header("Location: /index.html");
exit(); // important!
}

I cannot see where $mailsent is being set, so must assume you really want to do this:


if (mail($recipient, $subject, $msg, $mailheaders) === true){

header("Location: /index.html");
exit(); // important!
}

Because if you read the manual very carefully on the [fphp]mail/fphp page in the first highlighted box it states:

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

I draw your attention to “bool” that means mail will return either true or false, it won’t return a string or nice message, just true or false.

So that is something you can fork your code on with a conditional check,
if (true)
do this
else
do that

ok, I’ll try this code now. thanks a lot :slight_smile:

I’d feel a whole lot better if you said you understand the principle of the idea I just placed before you - or asked me questions if you did not understand what the heck bool or boolean meant.

I’m not here to write code for you.

I know what boolean is, I’ve done some JavaScript. Boolean can be only true or false. They are can not be strings or arrays.

I believe I need another part of code you wrote, the one to do something in IF mail is not true, if it does not validate.

I’m not quite sure what header(“Location: /index.html”); means. The second part says where it should be redirected, but I have to check ‘header’.

Entering “PHP header” into google will fetch up [fphp]header[/fphp] - a PHP function which is similar to the JS location.href=xxxxxx