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

How to set up email with Outlook 2003?

Follow the steps below to set up Outlook 2003 to retrieve email from our mail server. ...

Setup Email in iPhone or iPad

1.) Go to  Settings >>  Mail, Contacts, Calendars2.) To add a new Email account , choose...

What is the essence of PHP encryption(using crypt(),mcrypt(),etc)if data on transit isn't safe?

The apathetic response is, of course, "there is no point." If you allowed a login over normal...

How to refresh a page?

...

How can I call a command line executable from within PHP?

Check out the "Program Execution functions" here :...