PHP傳送郵件

2021-08-25 17:24:34 字數 3172 閱讀 4806

使用下面的傳送類

smtp.class.php:

<?php

set_time_limit(120);

class smtp

/* main function??? */

/function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "")

$header .= "to: ".$to."\r\n";

if ($cc != "")

//$header .= "from: $from<".$from.">\r\n";

$header .= "from: ".$from."\r\n";

$header .= "subject: ".$subject."\r\n";

$header .= $additional_headers;

$header .= "date: ".date("r")."\r\n";

$header .= "x-mailer: 72e.net (php/".phpversion().")\r\n";

list($msec, $sec) = explode(" ", microtime());

$header .= "message-id: <".date("ymdhis", $sec).".".($msec*1000000).".".$mail_from.">\r\n";

$to = explode(",", $this->strip_comment($to));

if ($cc != "")

if ($bcc != "")

foreach ($to as $rcpt_to)

if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body))

else

fclose($this->sock);

$this->log_write("disconnected from remote host\n");

}return $sent;

}/* private functions */

//function smtp_send($helo, $from, $to, $header, $body = "")

#auth

if($this->auth)

if (!$this->smtp_putcmd("", base64_encode($this->pass)))

//if (!$this->smtp_putcmd("mail", "from:".$from.""))

if (!$this->smtp_putcmd("rcpt", "to:<".$to.">"))

function smtp_sockopen($address)

else }/

function smtp_sockopen_relay()

/function smtp_sockopen_mx($address)

function smtp_eom()

/function smtp_ok()

function smtp_putcmd($cmd, $arg = "")

else

}fputs($this->sock, $cmd."\r\n");

$this->smtp_debug("> ".$cmd."\n");

//echo "cmd=".$cmd."\r\n";

return $this->smtp_ok();}//

function smtp_error($string)

function log_write($message)

$message = date("m d h:i:s ").get_current_user()."[".getmypid()."]: ".$message;

if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a")))

flock($fp, lock_ex);

fputs($fp, $message);

fclose($fp);

return true;}/

function strip_comment($address)

return $address;}//

function get_address($address)

function smtp_debug($message)

}} // end class

?>

傳送程式:

mail.php

<?php

include "smtp.class.php";

$smtpserver = ""; //您的smtp伺服器的位址

$port = 25 ; //smtp伺服器的埠,一般是25 或者465(ssl)

$smtpuser = ""; //您登入smtp伺服器的使用者名稱

$smtppwd = ""; //您登入smtp伺服器的密碼

$mailtype = "html"; //郵件的型別,可選值是 txt 或 html ,txt 表示是純文字的郵件,html 表示是 html格式的郵件

$sender = "//發件人,一般要與您登入smtp伺服器的使用者名稱($smtpuser)相同,否則可能會因為smtp伺服器的設定導致傳送失敗

$smtp =   new smtp($smtpserver,$port,true,$smtpuser,$smtppwd,$sender);

$smtp->debug = true; //是否開啟除錯,只在測試程式時使用,正式使用時請將此行注釋

$to = ***x@***.***; //收件人,多個收件人請用英文逗號分開即可

$subject = "這是郵件主題-html\\\*";

$body = "";

$send=$smtp->sendmail($to,$sender,$subject,$body,$mailtype);

if($send==1)

else

?>

此外還需要建立log檔案,以便記錄日誌.

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伺服器的...