php傳送郵件

2021-08-09 04:15:29 字數 4243 閱讀 4746

新建檔案 smtp.clss.php  裡面**不用修改!

**如下:

<?php

class smtp_classelse

}function addto($address,$name)

function addcc($address,$name)

function addbcc($address,$name)

function addreplyto($address,$name)

if($name=="")

$current_count=count($this->attachment);

$this->attachment[$current_count][0]=$path;

$this->attachment[$current_count][1]=$name;

$this->attachment[$current_count][2]=$type;

}function smtp_open($host,$port,$timeout)

$this->get_lines();

return true;

}function smtp_close()

function send()

# if smtp need authorization

if($this->authlogin==true)

# send auth login command

if($this->error_status==false)

}# username and password authorization

if($this->error_status==false)

}}else

}# define sender email

if($this->error_status==false)

}# define sending email address

$this->reset_current_count();

while($this->error_status==false and $this->current_countto))

$this->reset_current_count();

while($this->error_status==false and $this->current_countcc))

$this->reset_current_count();

while($this->error_status==false and $this->current_countbcc))

# send mail

$this->smtp_data("");

# close smtp connection

$this->smtp_close();

# return send email success or fail

if($this->error_status)else

}function reset_current_count()

function smtp_rcpt($emailto)

}function smtp_auth()

function smtp_data($message)

}if($this->error_status==false)

$this->create_body();

$this->send_lines("");

# add attachment

if(count($this->attachment)>0)

# end of message

$this->send_lines(".");}}

function create_header()

if(count($this->cc)>0)

if(count($this->replyto)>0)

$this->send_lines("subject: ".$this->subject);

$this->send_lines("x-priority: ".$this->priority);

$this->send_lines("x-mailer: ".$this->version);

$this->send_lines("x-original-ip: ".getenv("remote_addr"));

$this->send_lines("content-transfer-encoding: ".$this->encoding);

$this->send_lines("return-path: ".$this->fromemail);

$this->send_lines("mime-version: 1.0");

if(count($this->attachment)>0)else

$this->send_lines("");

}function create_body()

$this->send_lines(ereg_replace("\n","\r\n",$this->body));

}$email_string=$type.": ";

for($i=0;$i

if($i>0)

if(trim($email[$i][1])!= "")else

}return($email_string);

}for($i=0;$iattachment);$i++)

}function ishtml($status)else

}function error_handler($message)

if($message!="")else

}function get_lines()

}return $data;

}function send_lines($command)}

下面是乙個測試檔案:

<?php

require_once('smtp.class.php');

$mail=new smtp_class;

$mail->host 

= "smtp.qq.com";  // smtp server. like smtp.21cn.com

$mail->port 

= 25;  // smtp port. default: 25;

$mail->timeout 

= 10;  // smtp connection timeout. default: 10;

$mail->timezone 

= "+0800";  // time zone. default: "+0000";

$mail->priority 

= 3;  // email priority default: 3 (1=high,3=medium or 5=low);

$mail->charset 

= "utf-8";  // character set.

$mail->wordwrap 

= 0;  // characters per line. 0 for umlimit characterc per line

$mail->ishtml 

= true;  // html email. default: false (true or false);

$mail->mailerdebug 

= true;  // display smtp error. default: false (true or false);

$mail->authlogin 

= true;  // using smtp authorization. default: false (true or false);

$mail->authuser 

= "賬號";  // smtp username  我用qq郵箱測試通過(到qq郵箱開通smtp服務)

$mail->authpass 

= "密碼";  // smtp password  郵箱登陸密碼

# email address and content start here

$mail->from("傳送郵箱位址

","webdna"); 

最好和上面的賬號一直

$mail->addto("接受郵件位址","guest name");

$mail->subject="e-mail to website";

$mail->body="測試郵件"; 

//這裡就是你要發的內容

if(!$mail->send())else

?>

php郵件傳送

今天要用到php的郵件傳送,便用phpmailer弄了個 類檔案 emaillclass.php class phpmailer function send addr,fromname,title,content smtp array array ehlo hello lb,220,250 ehlo...

php 郵件傳送

2 修改class.phpmailer.php 增加變數 fromemail 修改下面內容 成如下內容 if this fromname else result this headerline from this fromemail.fromname result this headerline r...

php 傳送郵件

results wpdb query sql 傳送郵件提醒有人申請 smtpserver smtp.qq.com smtp伺服器,如 smtp.qq.com smtpserverport 25 smtp伺服器端口,一般為25 smtpusermail 117 x837 qq.com smtp伺服器的...