利用 PHPMailer发送邮件(可发送 HTML内容,图片,附件)
利用phpmailer发送邮件(可发送 html内容,图片,附件),phpmailer是一个用于发送电子邮件的php类,他比php自带的函数mail强多了,phpmailer可以到官方下载。
下面来看一个只发送文本的实例:
<?php require("class.phpmailer.php"); $mail = new phpmailer(); $mail->ismail(); $mail->addaddress("email@example.com"); $mail->subject = "test 1"; $mail->body = "test 1 of phpmailer."; if(!$mail->send()) { echo "error sending: " . $mail->errorinfo;; } else { echo "letter sent"; } /* $mail->ismail(); 必须发送 issendmail - via sendmail command. isqmail - directly via qmail mta. issmtp - via smtp server. 这里有一个使用smtp样本,我们假设该smtp需要授权,如果in't nessesary,只写$邮件> smtpauth = 0;,要使用的服务器数量使用semicolumn为分隔符. */
require("class.phpmailer.php"); $mail = new phpmailer();$mail = new phpmailer(); $mail->issmtp(); $mail->host = "smtp1.example.com;smtp2.example.com"; $mail->smtpauth = true; $mail->username = 'smtpusername'; $mail->password = 'smtppassword'; $mail->addaddress("email@example.com"); $mail->subject = "test 1"; $mail->body = "test 1 of phpmailer."; if(!$mail->send()) { echo "error sending: " . $mail->errorinfo;; } else { echo "letter is sent"; } /* 添加有关发件人inforation,使用以下功能: mail->from="mailer@example.com"; $mail->fromname="my site's mailer"; $mail->sender="mailer@example.com"; // indicates returnpath header $mail->addreplyto("replies@example.com", "replies for my site"); // indicates replyto headers for specifying various types of recepients use these: $mail->addaddress("mail1@domain.com", "recepient 1"); $mail->addcc("mail1@domain.com", "recepient 1"); $mail->addbcc("mail1@domain.com", "recepient 1"); 如何出现乱码可利用 $mail->charset="windows-1251";$mail->charset="utf-8"; 设置编码,如果要想发送邮件可以发送图片和附低年及html代码就在$mail-send()前面加如下代码: $mail->ishtml(true); $mail->addembeddedimage('logo.jpg', 'logoimg', 'logo.jpg'); // attach file logo.jpg, and later link to it using identfier logoimg $mail->body = "<h1 id="test-nbsp-nbsp-of-nbsp-phpmailer-nbsp-html">test 1 of phpmailer html</h1> <p>this is a test picture: <img src="/static/imghw/default1.png" data-src="cid:logoimg" class="lazy" / alt="利用 PHPMailer发送邮件(可发送 HTML内容,图片,附件) " ></p>"; $mail->altbody="this is text only alternative body."; 发送附件 $mail->ishtml(false); $mail->addattachment('www.phprm.com/invoice-user-1234.pdf', 'invoice.pdf'); // attach files/invoice-user-1234.pdf, */
添加有关发件人inforation,使用以下功能:
mail->from="mailer@example.com"; $mail->fromname="my site's mailer"; $mail->sender="mailer@example.com"; // indicates returnpath header $mail->addreplyto("replies@example.com", "replies for my site"); // indicates replyto headers for specifying various types of recepients use these: $mail->addaddress("mail1@domain.com", "recepient 1"); $mail->addcc("mail1@domain.com", "recepient 1"); $mail->addbcc("mail1@domain.com", "recepient 1");
文章网址:
随意转载^^但请附上教程地址。

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP development practice: Use PHPMailer to send emails to users in the MySQL database Introduction: In the construction of the modern Internet, email is an important communication tool. Whether it is user registration, password reset, or order confirmation in e-commerce, sending emails is an essential function. This article will introduce how to use PHPMailer to send emails and save the email information to the user information table in the MySQL database. 1. Install the PHPMailer library PHPMailer is

In web applications, it is often necessary to send emails to multiple recipients at once. PHP is a very popular web development language, and PHPMailer is a common PHP class library for sending emails. PHPMailer provides a rich interface, making sending emails in PHP applications more convenient and easy to use. In this article, we will introduce the methods and steps on how to use PHPMailer to send emails to multiple recipients. To download PHPMailer, you first need to go to the official website (

Mastering PHP and PHPMAILER: How to implement the automatic reply function for email sending? In modern society, email has become one of the important ways for people to communicate every day. Many websites or companies need to communicate with users through emails, and automatic reply to emails has become very important. This article will introduce how to use PHP and the PHPMailer library to implement the automatic reply function for email sending. Step 1: Get the user’s email information First, we need to get the user’s email information. On a website or application, use

How to send HTML mail with embedded images using PHP and PHPMAILER? HTML email is a richer and more personalized form of email that can insert pictures, links and styles into the email. Embedded images refer to sending images directly as part of the email in the HTML email instead of sending them as attachments. In PHP, we can use PHPMAILER to send HTML emails with embedded images. PHPMAILER is a powerful PHP email sending library

How to use Flask-Mail to send emails With the development of the Internet, email has become an important tool for people to communicate. When developing web applications, sometimes we need to send emails in specific scenarios, such as sending a welcome email after a user successfully registers, or sending a password reset email when a user forgets their password, etc. Flask is a simple and flexible Python Web framework, and Flask-Mail is an extension library for sending emails under the Flask framework. This article will introduce how to

PHP and PHPMAILER: How to implement anti-spam function for email sending? Introduction: In the Internet age, email has become an indispensable part of our daily life and work. However, with the popularity and use of email, the problem of spam has become increasingly serious, causing a lot of trouble to users. In order to solve this problem, this article will introduce how to use PHP and PHPMailer library to implement the anti-spam function of email sending. 1. Understand spam. Spam refers to those unsolicited

Python connects to the Alibaba Cloud interface to implement the email sending function. Alibaba Cloud provides a series of service interfaces, including email sending services. By connecting to the Alibaba Cloud interface through a Python script, we can quickly send emails. This article will show you how to use Python scripts to connect to the Alibaba Cloud interface and implement the email sending function. First, we need to apply for the email sending service on Alibaba Cloud and obtain the corresponding interface information. In the Alibaba Cloud Management Console, select the email push service and create a new email

PHP methods and precautions for sending attachment emails using the PHPMailer library. Email has become a very important way of communication in modern life. In many development projects, we need to use code to automatically send emails. At this time, the PHPMailer library is our best choice. PHPMailer is a library dedicated to sending emails in PHP. It can easily send emails, including HTML-formatted emails and attachments. This article will focus on how to send emails with attachments in the PHPMailer library.
