How to send email using PHP script?

For PHP, We provide pear mail using smtp authentication method , here is the code sample:

require_once "c:\php\pear\Mail.php";

$from = "Sandra Sender ";

$to = "Ramona Recipient ";

$subject = "Hi!";

$body = "Hi,\n\nHow are you?";

$host = "mail.example.com";

$username = "smtp_username";

$password = "smtp_password";

$headers = array ('From' => $from,

'To' => $to,

'Subject' => $subject);

$smtp = Mail::factory('smtp',

array ('host' => $host,

'auth' => true,

'username' => $username,

'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {

echo("

" . $mail->getMessage() . "

");

} else {

echo("

Message successfully sent!

");

}

?>

Please use your own mail credentials : mail.yourdomain.com as the email host.

Was this answer helpful?

 Print this Article

Also Read

What do you mean by Catch All Email ?

In short, the catch-all email function allows you to receive all incoming email that is addressed...

How can I take a list and make each row a value in an array?

If you have a text file that looks like this : john|orange|cow sam|green|goat...

How do I add user account to my domain's email ?

For DotNetPanel Account For the new sign-up account, when it is activated by default the main...

What is SPF record and How to enable it?

SPF provides a way for a domain to tell the world that mail "from" that domain should only arrive...

How to set up email with Outlook 2007

Configuring your email client: Outlook 2007 Open Outlook 2007. Click the Tools menu, and...