How to send email using PHP script?

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

<?php

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

 

$from = "Sandra Sender <sender@example.com>";

$to = "Ramona Recipient <recipient@example.com>";

$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("<p>" . $mail->getMessage() . "</p>");

 } else {

  echo("<p>Message successfully sent!</p>");

 }

?>

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

Je li Vam ovaj odgovor pomogao?

 Ispiši članak

Također pročitajte

What is Greylisting?

Greylisting (or graylisting) is a method of defending e-mail users...

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

How do I keep a copy of emails on the server with Outlook?

Open Outlook interface, and click on "Tools -> E-mail Accounts". Select "View or change...

Instructions for requesting SBC Port 25 Filter Removal

1. Visit the following web site : http://help.sbcglobal.net/servabuse.php 2. You may be prompted...

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