Home > php教程 > php手册 > 在PHP中用Socket发送电子邮件(四)

在PHP中用Socket发送电子邮件(四)

WBOY
Release: 2016-06-21 09:14:36
Original
1064 people have browsed it

下面给出一个实例。

邮件发送实例

  先给出一个最简单的实例:
1 include "sendmail.class.php3";
2 $email="Hello, this is a test letter!";
3 $sendmail=new send_mail("smtp.263.net", "limodou", true); //显示调示信息
4 if($sendmail->send("chatme@263.net", "chatme@263.net", "test", $email))
5 {
6 echo "发送成功!
";
7 }
8 else
9 {
10 echo "发送失败!
";
11 }
?>

第1行,装入send_mail类。
第3行,创建一个类的实例,且设置显示调示信息,如果不想显示,可以
    $sendmail=new send_mail("smtp.263.net");。
第4行,发送邮件。


很简单,不是吗?下面再给合以前的发送MIME邮件的例子,给出一个发送HTML附件的例子。


include "MIME.class.php3";
//注,在发送MIME邮件一文中,这个类文件名为MIME.class,在此处我改成这样的

$to = 'chatme@263.net'; //改为收信人的邮箱
$str = "Newsletter for ".date('M Y', time());

//信息被我改少了
$html_data = '

'. $str. '

Hello! This is a test!

';

//生成MIME类实例
$mime = new MIME_mail("chatme@263.net", $to, $str);

//添加HTML附件
$mime->attach($html_data, "", HTML, BASE64);

//注释掉,采用我的发送邮件处理
//$mime->send_mail();

//生成邮件
$mime->gen_email();

//显示邮件信息
//echo $mime->email."
";

//包含sendmail文件
include "sendmail.class.php3";

//创建实例
$sendmail=new send_mail("smtp.263.net", "limodou", true);

//发送邮件
$sendmail->send("chatme@263.net", "chatme@263.net", $str, $mime->email);

?>
  注释写的很清楚,就不再做更多的解释了。如果实际应用中,请将send_mail构造函数中的debug设为false或不写即可。




Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template