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 = “[email protected],[email protected]”; $subject = “Test mail”; $message = “Hello! This is a test email message.”; $from = “[email protected]”; $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 // send email |
These codes will be placed on a file called phpmailer.php or mailer.php, however it will be your discretion on how to name it. Also, 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.