Tip: Sending Email

Here is the sample code to send an email from PHP

<?php
	$email='someone@someserver.com';
	$subject='Test Email';
	$message='Hi! This is a test email';
	mail($email,$subject,$message);
 ?>

The above code sends a plain(non-html) email. If you want to send html email and also want to include sender info, you will have to provide a 4th parameter i.e. some headers like this

<?php
	$email='someone@someserver.com';
	$subject='Test Email';
	$message='Hi! This is a test email';
 
	$header="From : Admin <alex@myserver.com> \r\n";
	$header=$header. "Content-type:text/html";
 
	mail($email,$subject,$message,$header);
 ?>

The "\r\n" is a new line character used to separate multiple header properties

 

More PHP tips