Thursday, November 6, 2008

send email with php

php has very simple code to send email.
For this it has provided a file 'Mail.php' which we add and are ready to send email.

Below is the sample code-

require_once 'Mail.php';

//set to field
$to = "to@domain.com";
//set subject filed
$subject = "email verification";
//set from filed
$from = "from@domain.com";
//set content
$content = "Click below link to confirm registration. http://localhost/PROJECT/index.php"
//get host
$host = "mail.host.com";
$username = "username";
$password = "password";

$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);

$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
//send email
$mail = $smtp->send($to, $headers, $content);


And thus we are done with sending email with php.

No comments: