webMethods Learner

Icon

Reading, understanding, and trying to write it down

Sending mail with PHP using SMTP-auth (PEAR package)

To protect essentials network, servers, and customers from spamming, it requires the use of SMTP-auth for all methods of sending email. The basic PHP Mail function does not support SMTP-auth, therefore cannot be used.

To write your own PHP code to send email using SMTP-auth, there are PHP PEAR Mail package available for usage (which supports smtp-auth). PHP code sample below shows how to use this feature to send an email:


require_once "Mail.php";

/**************************************************
EDIT the following variables for your own use
***************************************************/
$from = "user@domain";
$to = "user2@domain2";

$subject = "Hi!"; //type in subject here

$host = "host_ip"; // Your domain
$username = "user"; // Your user / full email address
$password = "password"; // Password to your email address

/**************************************************
***************************************************/

$body = "Test";

foreach($_POST as $a => $b)
{
$body .= $a .": ". $b . "\n";
}
$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)) {
/**************************************************
ERROR MESSAGE
***************************************************/
?>

getMessage(); ?>
/**************************************************/
} else {
/**************************************************
SUCCESS MESSAGE
***************************************************/
?>
Message successfully sent!
/**************************************************/
}


?>

grabbed from here :-)

Filed under: PHP, ,

 

June 2012
M T W T F S S
« Jan    
 123
45678910
11121314151617
18192021222324
252627282930  
Follow

Get every new post delivered to your Inbox.