PHP Mail function

Program to Accepts Mail-Related Information
Index.html

Mail Form

To
Subject
Message

email.php
<?php
if (empty ($mailto) )
{
die ( “Recipient is blank! “) ;
}
if (empty ($mailsubject) )
{
$mailsubject=” ” ;
}
if (empty ($mailbody) )
{
$mailbody=” ” ;
}
$result = mail ($mailto, $mailsubject, $mailbody) ;
if ($result)
{
echo “Email sent successfully!” ;
}
else
{
echo “Email could not be sent.” ;
}
?>

Mail Function:

  • Using this function we can send an email from our application to destination mail-id.
  • It contains argument to address, subject, body and collection of headers.
  • Different type of mail headers are available From, cc, bcc, content type etc.
  • separator between one header and another.
Note

To Send the mail from application to destination mail-id SMTP server is required.

Program to Send the Mail
Email:
Subject:
Message:

<?php
if (isset($_REQUEST[’email’]))
{
$admin_email = “admin@gmail.com”;
$email = $_REQUEST[’email’];
$subject = $_REQUEST[‘subject’];
$comment = $_REQUEST[‘comment’];
mail($admin_email, “$subject”, $comment, “From:” . $email);
echo “Thank you for contacting us!”;
}
else
{
?>
<?php
}
?>

‚Äč

Leave a Reply

Your email address will not be published. Required fields are marked *