Sending mail using PHP

Here is an example script for sending out mail using php:

<?
// Please specify your Mail Server - Example: mail.yourdomain.com.
ini_set("SMTP","mail.YourDomain.com");

// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","25");

// Please specify the return address to use
ini_set('sendmail_from', 'ValidEmailAccount@YourDomain.com');

// Set parameters of the email
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From: $from";

// Mail function that sends the email.
mail($to,$subject,$message,$headers);
?>

If you are sending mail using a form on your website, we recommend you use PHP Form Mail.

Add Feedback