注意:我司虚拟主机除了fsock主机外,其它空间都不支持smtp发信的,请知悉。
fsock主机G型(双线):http://www.gzidc.com/web.php?m=FrontHost&a=details&product=superG-3
明珠HK fsock主机:http://www.gzidc.com/web.php?m=FrontHost&a=details&product=hongkong-7
require_once "Mail.php";
$from = " Sender <sender@example.com>";//发件人
$to = " Recipient <recipient@example.com>";//收件人
$subject = "Hi!"; //邮件标题
$body = "Hi,nnHow are you?";//邮件内容
$host = "mail.example.com";//SMTP服务器地址
$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("
" . $mail->getMessage() . "
");} else {
echo("
Message successfully sent!
");}
?>