search
HomeBackend DevelopmentPHP TutorialPHPMailer Send Email_PHP Tutorial

PHPMailer Send Email_PHP Tutorial

Jul 13, 2016 pm 05:39 PM
phpmailersuperiorDownunderandsharedblogsendarticleofOwnmail

刚刚出炉的自己博客文章来与大家共享下^_^,下面文章转载自我的博客:久酷博客
上篇文章PHP mail()方法发送邮件部分邮箱无法收到邮件问题 提到要介绍一下phpmailer这款免费开源的php 邮件程序,下面我们来看看吧,以下资料全部来自phpmailer官方网站:

PHPMailer 也是一个功能强大的邮件类

PHPMailer的主要功能特点:

支持邮件 s/mime加密的数字签名
支持邮件多个 TOs, CCs, BCCs and REPLY-TOs
可以工作在任何服务器平台,所以不用担心WIN平台无法发送邮件的问题的
支持文本/HTML格式邮件
可以嵌入image图像
对于邮件客户端不支持HTML阅读的进行支持
功能强大的发送邮件调试功能debug
自定义邮件header
冗余SMTP服务器支持
支持8bit, base64, binary, and quoted-printable 编码
文字自动换行
支持多附件发送功能
支持SMTP服务器验证功能
在Sendmail , qmail , Postfix , Gmail , Imail, Exchange 等平台测试成功
提供的下载文件中,包括内容详细的说明文档及示例说明,所以不用担心难于上手的问题!
PHPMailer 非常小巧、简单、方便、快捷
以上资料由Jiucool 翻译自phpmailer 官网,转载请注明!

Usage of PHPMailer (here is using gmail smtp to send emails as an example. Of course, sendmail pop and other methods are also supported):
First go to http://phpmailer.worxware.com/ to download the latest version of the package
After the download is completed, find the two classes class.phpmailer.php and class.smtp.php and put them in your own directory!
Then create a new php file and name it here: phpmail_jiucool.php
phpmail_jiucool.php The content is as follows:
I directly write the email sending module as a function postmail_jiucool_com(). You can call this function directly when using it. , the function content is:
function postmail_jiucool_com($to,$subject = "",$body = ""){
//Author:Jiucool WebSite: http://www.jiucool.com
/ /$to represents the recipient address $subject represents the email title $body represents the email body
//error_reporting(E_ALL);
error_reporting(E_STRICT);
date_default_timezone_set("Asia/Shanghai");// Set time zone Dongba District
require_once(class.phpmailer.php);
include("class.smtp.php");
$mail = new PHPMailer(); //new a PHPMailer object comes out
$body = eregi_replace("[]",,$body); //Perform necessary filtering on the email content
$mail->CharSet = "UTF-8";//Set the email encoding, The default is ISO-8859-1. If you send Chinese, this must be set, otherwise it will be garbled.
$mail->IsSMTP(); // Set to use SMTP service.
$mail->SMTPDebug = 1; Enable SMTP debugging
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // Enable SMTP authentication function
$mail->SMTPSecure = "ssl";                                                                                 // SMTP server port number
$mail->Username = "SMTP server username"; // SMTP server username
$mail->Password = "SMTP server password"; // SMTP server password
$mail- >SetFrom(Sender address, such as admin#jiucool.com #Replace with @, sender name);
$mail->AddReplyTo("Email reply address, such as admin#jiucool.com #Replace with @","Name of the person who responded to the email");
$mail->Subject = $subject;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer! - From www.jiucool.com"; // optional, comment out and test
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($ address, "recipient name");
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
//$mail->AddAttachment("images/phpmailer_mini .gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent! Congratulations, the email was sent successfully!"; 
                                                                                            

http://www.bkjia.com/PHPjc/486258.html

www.bkjia.com

http: //www.bkjia.com/PHPjc/486258.htmlTechArticleI just released my blog article to share with you ^_^, the following article is reproduced from my blog: Jiuku Previous blog article: PHP mail() method sends emails and some mailboxes cannot receive emails...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools