NameSilo

Mail()

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch
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:

PHP:
mail($to, $subject, $message, $headers);
you can either set the varaibles or enter them manually like this:

PHP:
mail([email protected], message subject, message , headers);
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"
PHP:
if(mail($to,$subject,$message,$headers)){
echo "Email Sent";
}else{
echo "Email Sending Failed";
}
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:
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";
}
The other emaple i mentioned at the begginig was the contact form, look at this form, it has both parts in one php page:
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";
}
}
?>
an example of it is available here .

I hope this is helpful and makes the mail() function clear and easier to use.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
CatchedCatched

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

New in Parking: updated way to act on many domains or inquiries at once
Your domain list and inquiry list now have a bar above and below the list. Check the items you want, then choose an action in the bar...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back