Install sendmail on the server
sudo apt-get install sendmail
Start sendmail
sudo /etc/init.d/sendmail start
Modify php.ini
[mail function] SMTP = localhost smtp_port = 25 sendmail_from = me@example.com
Function sendMail
<?php /* 调用PHPMailer发送电邮 * @param String $receiver 收件人 * @param String $sender 发件人 * @param String $sender_name 发件人名称如为空则用发件人地址代替 * @param String $subject 邮件主题 * @param String $content 邮件内容 * @param boolean $ishtml 是否html电邮 * @param Array $attachements 附件 * @return boolean */ function sendMail($receiver, $sender, $sender_name, $subject, $content, $ishtml=true, $attachments=array()) { include_once "class-phpmailer.php"; if(empty($receiver) || empty($sender) || empty($subject) || empty($content)){ return false; } $mail = new PHPMailer(); //$mail->IsSMTP(); // 经smtp发送 //$mail->Host = "smtp.gmail.com"; // SMTP 服务器 //$mail->Port = 465; // SMTP 端口 //$mail->SMTPSecure = 'ssl'; // 加密方式 //$mail->SMTPAuth = true; // 打开SMTP认证 //$mail->Username = "username"; // 用户名 //$mail->Password = "password"; // 密码 $mail->IsMail(); // using PHP mail() function 有可能會出現這封郵件可能不是由以下使用者所傳送的提示 $mail->From = $sender; // 发信人 $mail->FromName = $sender_name; // 发信人别名 $mail->AddReplyTo($sender); // 回覆人 $mail->AddAddress($receiver); // 收信人 // 以html方式发送 if($ishtml){ $mail->IsHTML(true); } // 发送附件 if($attachments){ if(is_array($attachments)){ $send_attachments = array(); $tmp_attachments = array_slice($attachments,0,1); if(!is_array(array_pop($tmp_attachments))){ if(isset($attachments['path'])){ array_push($send_attachments, $attachments); }else{ foreach($attachments as $attachment){ array_push($send_attachments, array('path'=>$attachment)); } } }else{ $send_attachments = $attachments; } foreach($send_attachments as $attachment){ $attachment['name'] = isset($attachment['name'])? $attachment['name'] : null; $attachment['encoding'] = isset($attachment['encoding'])? $attachment['encoding'] : 'base64'; $attachment['type'] = isset($attachment['type'])? $attachment['type'] : 'application/octet-stream'; if(isset($attachment['path']) && file_exists($attachment['path'])){ $mail->AddAttachment($attachment['path'],$attachment['name'],$attachment['encoding'],$attachment['type']); } } }elseif(is_string($attachments)){ if(file_exists($attachments)){ $mail->AddAttachment($attachments); } } } $mail->Subject = $subject; // 邮件标题 $mail->Body = $content; // 邮件內容 return $mail->Send(); } // DEMO $receiver = 'receiver@test.com'; $sender = 'sender@test.com'; $sender_name = 'sender name'; $subject = 'subjecct'; $content = 'content'; // 四種格式都可以 $attachments = 'attachment1.jpg'; $attachments = array('path'=>'attachment1.jpg', 'name'=>'附件1.jpg'); $attachments = array('attachment1.jpg','attachment2.jpg','attachment3.jpg'); $attachments = array( array('path'=>'attachment1.jpg', 'name'=>'附件1.jpg'), array('path'=>'attachment2.jpg', 'name'=>'附件2.jpg'), array('path'=>'attachment3.jpg', 'name'=>'附件3.jpg'), ); $flag = sendMail($receiver, $sender, $sender_name, $subject, $content, true, $attachments); echo $flag; ?>
The above is the content of PHPMailer - PHP email transport class. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

在Web应用程序中,往往需要将邮件一次性发送给多个收件人。PHP是一种很流行的Web开发语言,而PHPMailer是一种常见的发送邮件的PHP类库。PHPMailer提供了丰富的接口,使得在PHP应用程序中发送邮件变得更加方便和易于使用。在本篇文章中,我们将介绍如何使用PHPMailer向多个收件人发送邮件的方法和步骤。下载PHPMailer首先需要在官网(

如何使用PHP和PHPMAILER发送带有内嵌图片的HTML邮件?HTML邮件是一种更加丰富和个性化的邮件形式,可以在邮件中插入图片、链接和样式。而内嵌图片是指在HTML邮件中直接将图片作为邮件的一部分发送,而不是通过附件方式发送。在PHP中,我们可以借助PHPMAILER来发送带有内嵌图片的HTML邮件。PHPMAILER是一个功能强大的PHP邮件发送类库

PHP和PHPMAILER:如何实现邮件发送的防垃圾邮件功能?引言:在互联网时代,电子邮件已经成为了我们日常生活和工作中不可或缺的一部分。然而,随着电子邮件的普及和使用,垃圾邮件问题日益严重,给用户带来了诸多困扰。为了解决这个问题,本文将介绍如何利用PHP和PHPMailer库实现邮件发送的防垃圾邮件功能。一、了解垃圾邮件垃圾邮件(Spam),指的是那些未经

掌握PHP和PHPMAILER:如何实现邮件发送的自动回复功能?在现代社会中,电子邮件成为了人们日常沟通的重要方式之一。许多网站或者企业都需要通过邮件与用户进行沟通和交流,并且自动回复邮件变得非常重要。本文将介绍如何使用PHP和PHPMailer库实现邮件发送的自动回复功能。第一步:获取用户的邮件信息首先,我们需要获取用户的邮件信息。在网站或者应用程序中,用

PHP使用PHPMailer库发送附件邮件的方法和注意事项邮件在现代生活中已经成为了非常重要的一种通信方式。在很多开发项目中,我们需要使用代码自动发送邮件,这时候PHPMailer库就是我们的不二之选。PHPMailer是一个专门用于PHP发送邮件的库。它可以方便地发送邮件,包括HTML格式的邮件和附件。本文将着重介绍PHPMailer库中如何发送带附件的邮

如何使用PHP和PHPMailer发送带有图片的HTML邮件?邮件在现代通信中扮演着重要的角色,但是发送带有图片的HTML邮件可能会让一些PHP开发者感到困惑。在本文中,我们将介绍如何使用PHP和PHPMailer来发送带有图片的HTML邮件。我们将提供代码示例来帮助您更好地理解如何实现这一目标。首先,我们需要确保PHPMailer库已经安装在我们的项目中

如何使用PHP和PHPMailer发送HTML格式的邮件?随着互联网的发展,电子邮件已经成为人们日常沟通的重要工具。在开发网站和应用程序时,我们常常需要使用PHP和PHPMailer来发送邮件。本文将为您介绍如何使用PHP和PHPMailer发送HTML格式的邮件,并提供相应的代码示例。第一步:准备工作在开始之前,您需要确保已经安装了PHP和PHPMaile

CakePHP是一个基于MVC模式的PHP开源框架,旨在为开发者提供高效、可扩展、易于维护的Web应用程序开发环境。其中,邮件功能一直是Web应用程序的重要组成部分之一。为了方便开发者使用邮件功能,在CakePHP中已经封装了PHPMailer类库。PHPMailer是一款常用的邮件发送类库,支持发送HTML邮件、附件、抄送、邮件队列和SMTP验证等功能。本


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

WebStorm Mac version
Useful JavaScript development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Atom editor mac version download
The most popular open source editor