Home » Hosting Tutorials » Code Sample » Send email using PHP mail() function

Send email using PHP mail() function

Send email using PHP mail() function

PHP has built-in mail() function which can be used to send email without authentication. You just need to make sure that server is properly configured to relay email via PHP script.

When you use PHP mail(), it does not use SMTP authentication to relay email. Following us the sample script to send email using PHP mail() function:

<?php
$to = "somebody@example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster@example.com" . "\r\n" .
"CC: somebodyelse@example.com";

mail($to,$subject,$txt,$headers);
?>

Above code will relay emails using local mail server or MTA without any authentication.

Sharing is caring!

Leave a Comment

Your email address will not be published. Required fields are marked *