Sample Script in Sending Email via PHP

PHP has a function that can let you send email. This is the mail() function. This requires three mandatory arguments that specify the recipient’s email address, the subject of the message and the actual message. 

This function is like sending automated response to your customers or website viewers. Below are the sample PHP scripts: 

Code 1:


$to = “,”;

$subject = “Test mail”;

$message = “Hello! This is a test email message.”;

$from = “”;

$headers = “From:” . $from;


echo “Mail Sent.”;


Code 2:

// the message
$msg = “First line of text\nSecond line of text”;

// use wordwrap() if lines are longer than 70 characters
$msg = wordwrap($msg,70);

// send email
mail(“”,”My subject”,$msg);

These codes will be placed on a file called phpmailer.php or mailer.phphowever it will be your discretion on how to name itAlso, change necessary information for the scripts to the correct ones. 

If you’re sending through an external server, you can go to this guided link to mail script with external server. 

Please don’t hesitate to contact Singapore or Australia Support Team if you have further queries. 

(Visited 338 times, 1 visits today)

Was this article helpful?

Related Articles