Shrikanth Buds Shrikanth Buds - 2 months ago 16
PHP Question

How to make your own mailing services like gmail or yahoo

I am a noob to php and database...But i have an idea to perform mail operations on my own webserver(i.e just by database operations)but i really dont have any idea of how to send mail to external websites like gmail..and also i look forward to make my own email-addresses like ex:-myownemail@localhost...i have searched the google multiple times but i couldnt find any answer that i could understand..can anyone tell me in simple words on how to do this?

Answer Source

First you need to have a webhost, grab a free one for testing purposes which supports mail function. Then after you are done setting up your host, try the following.

To send a mail, since you don't care if it goes to spam, use this simple php code:

<?php
$to = "xyz@somedomain.com";
$subject = "This is subject";

$message = "<b>This is HTML message.</b>";
$message .= "<h1>This is headline.</h1>";

$header = "From:abc@somedomain.com \r\n";
$header = "Cc:afgh@somedomain.com \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";

$retval = mail ($to,$subject,$message,$header);

if( $retval == true )
{
    echo "Message sent successfully...";
}
else
{
    echo "Message could not be sent...";
}
?>

If you just want to read mails using PHP, PHP has native functions to talk to IMAP, NNTP and POP mailboxes.