1. Set up the variables:
    $to = "email@address.com"; //where the email will go 
    $subject = "Our Subject"; //the subject 
    $message = "The message to send"; //the message 
    $from = "you@email.com"; //from email 
    $header = "From: $from"; //header including the from email 
  2. Sending the email:
    mail($to, $subject, $message, $header); //send the email 
  3. Sending the email and returning a success or failure message
    echo (mail($to, $subject,$message, $header)) ? "Email sent" : "Error sending email" ; 
  4. Setting header to send html email:
    $header = "MIME-Version: 1.0" . "\r\n"; 
    $header .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; //add content type 
    $header .= "From: $from"; //header including the from email 
  5. Creating a function to send emails:
    function mailit ($to,$subject,$message,$from){ 
    $headers = "MIME-Version: 1.0" . "\r\n"; 
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; 
    $headers .= "From: <$from>" . "\r\n"; 
    return (mail($to, $subject,$message, $headers)) ? TRUE : FALSE; 


    $to = "email@address.com"; //where the email will go 
    $subject = "Our Subject"; //the subject 
    $message = "MessageThe html message"; //the message 
    $from = "you@email.com"; //from email 
    echo (mailit($to,$subject,$message,$from )==FALSE) ? "Sending Failed!" : "Mail sent!" ; 
Sending emails with php
Tagged on:     

Leave a Reply

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