- Impact
- 9
I think is subforum is a great idea, so i decided to do something in it. A famous function, yet mis-used is mail().
Mail function can be used in several ways, eg a contact form and auto-senders suitable for confirming registeration.
Ok the function is used like this:
you can either set the varaibles or enter them manually like this:
Although its prefered to use variables becuae its easier to use and modify later.
To make sure the message was sent correctly you can use the following "if block"
If you are making an autosender you add this to the page that has the email address passed in most propably by a form, so you do this:
The other emaple i mentioned at the begginig was the contact form, look at this form, it has both parts in one php page:
an example of it is available here .
I hope this is helpful and makes the mail() function clear and easier to use.
Mail function can be used in several ways, eg a contact form and auto-senders suitable for confirming registeration.
Ok the function is used like this:
PHP:
mail($to, $subject, $message, $headers);
PHP:
mail([email protected], message subject, message , headers);
To make sure the message was sent correctly you can use the following "if block"
PHP:
if(mail($to,$subject,$message,$headers)){
echo "Email Sent";
}else{
echo "Email Sending Failed";
}
PHP:
$to="[email protected]";
$from=$_POST['email'];
$message="my message";
$subject="Subject of message";
$headers = "From: $from";
if(mail($to,$subject,$message,$headers)){
echo "Email Sent messaage";
}else{
echo "Email Sending Failed mesasage";
}
PHP:
<?php
if(!isset($submit)){
echo "<form action='$_SERVER[PHP_SELF]' method='post'>
<p>Name: <input type='text' name='name'><br><p>
<p>Email: <input type='text' name='email'><br><p>
Message: <br>
<textarea name='message' cols='40' rows='15'></textarea><br>
<input type='submit' name='submit' value='send'>
</form>";
}else{
$to="[email protected]";
$from=$_POST['email'];
$message=$_POST['message'];
$subject="Website Contact Form";
$submit=$_POST['submit'];
$headers = "From: $from";
if(mail($to,$subject,$message,$headers)){
echo "Email Sent";
}else{
echo "Email Sending Failed";
}
}
?>
I hope this is helpful and makes the mail() function clear and easier to use.






