Simple PHP Code Send Email
Posted by in PHP June 28, 2011 1 Comment

I’ve just order a Cloud and is setting my virtual server on that cloud. After installed LAMP (Apache, MySQL and PHP) on CentOS server, I continue to check whether the PHP mail() function is working.

Below is the content of the test email PHP file. It’s just for testing purpose so the recipient is hard code without any email format validation.

Note: please replace the “your-email@your-domain.com” on line 2 with your real email address.

<?php
	$to = "your-email@your-domain.com";
	$subject = "Hello, it is a test email";
	$body = "Congratulation! The PHP Mail function is working";
	if (mail($to, $subject, $body)) 
	{
		echo("<p>Message is sent successful!</p>");
	} 
	else 
	{
		cho("<p>Message delivery failed...</p>");
	}
?>

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at hoan@4rapiddev.com
  • hoanhuynh

    A simply code for ASP:
    < %
    Set myMail=CreateObject("CDO.Message")
    myMail.Subject="Sending email with CDO"
    myMail.From="mymail@mydomain.com"
    myMail.To="someone@somedomain.com"
    myMail.TextBody="This is a message."
    myMail.Send
    set myMail=nothing
    %>