function sendBySmtp() { $mail = new MailSmtp(); $mail->setFrom($this->sender); //设置发件人 $mail->setReceiver("*****@*****.**"); //设置收件人,多个收件人,调用多次 //$mail->addAttachment("XXXX"); //添加附件,多个附件,调用多次 $mail->setMail("test主题", "test内容"); //设置邮件主题、内容 支持发送纯文本邮件和HTML格式的邮件 $mail->sendMail(); //发送 }
/** * SMTP mail testing utility. * * @since 141111 First documented version. * * @note This method always (ALWAYS) sends email in HTML format; * w/ a plain text alternative — generated automatically. * * @param string|array $to Email address(es). * @param string $subject Email subject line. * @param string $message Message contents. * @param string|array $headers Optional. Additional headers. * @param string|array $attachments Optional. Files to attach. * * @return \stdClass With the following properties: * * • `to` = addresses the test was sent to; as an array. * • `via` = the transport layer used in the test; as a string. * • `sent` = `TRUE` if the email was sent successfully; as a boolean. * • `debug_output_markup` = HTML markup w/ any debugging output; as a string. * • `results_markup` = Markup with all of the above in test response format; as a string. */ public function smtpTest($to, $subject, $message, $headers = [], $attachments = []) { $to = array_map('strval', (array) $to); // Force array. $via = 'smtp'; // Via SMTP in this case. $sent = false; // Initialize as `FALSE`. if ($this->isSmtpEnabled()) { // Can use SMTP; i.e. enabled? $mail_smtp = new MailSmtp(true); // Single instance w/ debugging. $sent = $mail_smtp->send($to, $subject, $message, $headers, $attachments); $debug_output_markup = $this->plugin->utils_string->trimHtml($mail_smtp->debugOutputMarkup()); } else { $debug_output_markup = __('Complete failure; configuration incomplete.', 'comment-mail'); } $results_markup = $this->testResultsMarkup($to, $via, $sent, $debug_output_markup); return (object) compact('to', 'via', 'sent', 'debug_output_markup', 'results_markup'); }
<?php include_once 'MailSmtp.class.php'; $body = <<<EOT <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh" dir="ltr"> <head> <meta http-equiv="x-ua-compatible" content="ie=7" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="generator" content="Editplus4PHP" /> <meta name="keywords" content="Editplus4PHP" /> <meta name="description" content="Editplus4PHP" /> <meta name="author" content="Leo" /> <title>Example | xHTML1.0</title> </head> <body> <p>你好 wangchao</p> <p><b>认证地址:</b><a href="http://sadjs.com">http://sadjs.com</a></p> </body> </html> EOT; //邮件发送 $subject = "测试邮件"; $smtp = new MailSmtp('smtp.163.com', 25, true, '3345191837', '10562782800'); $smtp->send_mail('*****@*****.**', '*****@*****.**', $subject, $body, "HTML");
<?php //测试是smtp发送邮件 //by indraw //2004/11/15 error_reporting(E_ERROR | E_WARNING | E_PARSE); require "MailSmtp.class.php"; //----------------------------------------------------------------------------- $smtpserver = "smtp.163.com"; //SMTP邮件服务器 $smtpserverport = 25; //SMTP端口号 $smtpusermail = "*****@*****.**"; //SMTP发送邮件地址 $smtpuser = "******"; $smtppass = "******"; //SMTP邮件密码 $smtpemailto = "*****@*****.**"; //目标邮件地址 $mailsubject = "Test Subject"; //邮件主题 $mailbody = "<h1>This is a test mail</h1>"; //邮件内容 $mailtype = "HTML"; //邮件发送方式(HTML/TXT) $smtp = new MailSmtp($smtpserver, $smtpserverport, true, $smtpuser, $smtppass); //这里面的一个true是表示使用身份验证,否则不使用身份验证. $smtp->show_debug = TRUE; //是否显示发送的调试信息 $smtp->send_mail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype); //-------------------------------------------------------------------------------