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 Email Forwarding?

Basically email forwarding allows you to create a unique email account which will...

Where can I get documentation for the Zend API?

First, here's the official website: http://www.zend.com/en/The official documentation for the...

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 do you mean by Catch All Email ?

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

What is Greylisting?

Greylisting (or graylisting) is a method of defending e-mail users against spam. A mail transfer...