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 do I setup Outlook Express?

Please note, replace yourdomain.com with your actual domain name.   1. Open Express. ...

How to redirect from php page to another php page?

For redirecting, you can use the PHP header() function like so : header("Location:...

How to set up email with Outlook 2007

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

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...

What is Greylisting?

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