龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

php 用Pear Mail发邮件

时间:2015-03-11 11:28来源:网络整理 作者:网络 点击:
分享到:
用Pear Mail发邮件 **[PHP]代码**[代码片段(48行)]

[PHP]代码

<?php
error_reporting(E_ALL);

require 'Mail.php';
require 'Mail/mime.php';

$text = "Text version of email\nMessage made with PHP";
$html = '<html><body>HTML version of email<br />';
$html .= 'Message made with <img src="12345" /></body></html>';
$crlf = "\n";

$from = 'from_address@163.com';
$to   = 'to_address@qq.com';
$password = '123456';

$mail_config=array(
        "host"=>"smtp.163.com",
        "port"=>25,
        "auth"=>true,
        "username"=>$from,
        "password"=>$password,
        "from"=>$from,
);

$hdrs = array(
        'From'=>$from,
        'Subject'=>'Test HTMl Email with Embedded Image'
);
$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->addHTMLImage('php.gif','image/gif','12345',true);
$mime->setHTMLBody($html);
$body = $mime->get();
$hdrs = $mime->headers($hdrs);

$mail = Mail::factory('smtp',$mail_config);
$succ = $mail->send($to,$hdrs,$body);

if (PEAR::isError($succ))
{
    echo 'Email sending failed: ' . $succ->getMessage();
}
else
{
    echo 'Email sent succesfully';
}
?>

精彩图集

赞助商链接