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:

<?php

$to = “someone@example.com,someother@example.com”;

$subject = “Test mail”;

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

$from = “someonelse@example.com”;

$headers = “From:” . $from;

mail($to,$subject,$message,$headers);

echo “Mail Sent.”;

?>

Code 2:

<?php
// 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(“someone@example.com”,”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 243 times, 1 visits today)