As before an example with some addons, read it carefully
PHP Code:
<?php if(!empty($_POST['text']) && !empty($_POST['mail']))
/* empty() is a function to check if a variable is empty or not
the "!" means "not"
&& is used in "if" and "while" to add some condition, it means "AND"
and could be replaced by "or" or "||" (the same thing)*/
{
$to = 'myname@example.com';
$subject = 'Mail from my website';
$message = $_POST['text']; // you could use directly $_POST['text']
$headers = 'From: '.$_POST['mail']."\r\n" .
'Reply-To: '.$_POST['mail']."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
?>
<form method="post">Mail : <input type="text" name="mail">
<br>You're text<texterea name="text"></texterea>
<br><input type="submit" value="send"></form>
As before I put 5 errors on the next code, who's the same as the up. try to find them and search the reason why :
PHP Code:
<?php if(!empty($_POST['text']) & empty($_POST['mail'])
/* empty() is a function to check if a variable is empty or not
the "!" means "not"
&& is used in "if" and "while" to add some condition, it means "AND"
and could be replaced by "or" or "||" (the same thing)*/
{
$to = 'myname@example.com';
$subject = 'Mail from my website';
$message = $_POST['text']; // you could use directly $_POST['text']
$headers = 'From: '.$_POST['mail'] .
'Reply-To: '.$_POST['mail']."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers)
}
?>
<form method="post">Mail : <input type="text" name="mail">
<br>You're text<texterea name="text"></texterea>
<br><input type="submit" value="send"></form>