Hantar email guna server authentication

Solution nie akan solvekan problem kalau kita nak send email guna php code dan email account kita tu kena authenticate, contoh macam guna Microsoft Exchange sever dan server tersebut berada kat tempat lain.

Sending Mail from PHP Using SMTP Authentication – Example

<?php
 require_once "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"; 		//server hang pa
 $username = "smtp_username";		//username iaitu email penuh termasuk @
 $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>");
  }
 ?>

sumber rujukan : http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm

mengapa ambil masa yang lama:

1. tak tau keyword untuk solve prob nie. keyword dia adalah Sending Mail from PHP Using SMTP Authentication

2. dok cuba mercury / stand alone email server ( takut juga kalau kalau tertakeover server exchange jenuh la kena tiau ngan IT .

3. on off on off on off fedup buat sat macam nak jadik tapi tak jadi pakai cara nu  tak jadi juga banyak kerja etc etc etc.

kesimpulannya .. cuba la sampai muntah darah insyaAllah akan bertemu jalan jua.

Leave a comment

Your email address will not be published. Required fields are marked *