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.
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

I'm new to PHP, where should I start?

Well, try this.The official PHP web site as a lot of useful information:   ...

What's the best way to start writing a PHP program?

Firstly figure out, on paper, exactly what you want to do. Otherwise, you'll just be coding...

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

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

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