注意:我司虛擬主機(jī)除了fsock主機(jī)外,其它空間都不支持smtp發(fā)信的,請(qǐng)知悉。
fsock主機(jī)G型(雙線):http://www.conceptioncalc.com/web.php?m=FrontHost&a=details&product=superG-3
明珠HK fsock主機(jī):http://www.conceptioncalc.com/web.php?m=FrontHost&a=details&product=hongkong-7
<?php
require_once "Mail.php";
$from = " Sender <sender@example.com>";//發(fā)件人
$to = " Recipient <recipient@example.com>";//收件人
$subject = "Hi!"; //郵件標(biāo)題
$body = "Hi,nnHow are you?";//郵件內(nèi)容
$host = "mail.example.com";//SMTP服務(wù)器地址
$username = "smtp_username";//發(fā)件人用戶名
$password = "smtp_password";//發(fā)件人密碼
$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>");
}
?>