Sending email using PHP

Posted on October 1 2009 by zemog

In this tutorial I will teach you how to make a program to send email. You can use the script into your website like contact us form where your visitor can type something and the message will be sent to your mailbox.

PHP has a mail function that is very easy to use. This function has the following parameters
to = email address to send to
subject = the subject of the email
message = the content of your email
headers = used to add extra headers like From, Cc, and Bcc. Multiple extra headers should be separated with a CRLF (\r\n).

Sample code using mail function


<?php

// Your email address

$email = “you@example.com”;

// The subject

$subject = “Enter your subject here”;

// The message

$message = “Enter your message here”;

mail($email, $subject, $message, “From: $email”);

echo “The email has been sent.”;

?>


Share This Post

Comments are closed.