phpmailer is a free php email sending plug-in. We can use phpmailer to log in to our designated email and then use this email to automatically send us emails. This free email address like 163 and Sina all support it. Okay Without further ado, let’s take a look at a phpmainer 163 email to send an email.
There is no local email server. It is a good choice to use a ready-made SMTP server to send emails. The tool used here is phpmailer (Version 5.2.0), and the SMTP servers are gmail and 163.
1. Script to send using gmail
include("class.phpmailer.php"); include("class.smtp.php"); //获取一个外部文件的内容 $mail = new PHPMailer(); $body = file_get_contents('contents.html'); $body = eregi_replace("[\]",'',$body); //设置smtp参数 $mail->IsSMTP(); $mail->SMTPAuth = true; $mail->SMTPKeepAlive = true; $mail->SMTPSecure = "ssl"; $mail->Host = "smtp.gmail.com"; $mail->Port = 465; //填写你的gmail账号和密码 $mail->Username = "yourname@gmail.com"; $mail->Password = "password"; //设置发送方,最好不要伪造地址 $mail->From = "yourname@gmail.com"; $mail->FromName = "Webmaster"; $mail->Subject = "This is the subject"; $mail->AltBody = $body; $mail->WordWrap = 50; // set word wrap $mail->MsgHTML($body); //设置回复地址 $mail->AddReplyTo("yourname@gmail.com","Webmaster"); //添加附件,此处附件与脚本位于相同目录下 //否则填写完整路径 $mail->AddAttachment("attachment.jpg"); $mail->AddAttachment("attachment.zip"); //设置邮件接收方的邮箱和姓名 $mail->AddAddress("toname@gmail.com","FirstName LastName"); //使用HTML格式发送邮件 $mail->IsHTML(true); //通过Send方法发送邮件 //根据发送结果做相应处理 if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message has been sent"; }
2. Script to send email using 163
You only need to change the SMTP configuration and account password, the SMTP configuration is as follows
//设置smtp参数 //注意这里不需要ssl协议 $mail->IsSMTP(); $mail->SMTPAuth = true; $mail->SMTPKeepAlive = true; $mail->Host = "smtp.163.com"; $mail->Port = 25;
To pass the test in the local wampserver environment, you need to enable the php_openssl extension.
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
php methods to operate MySQL database and session dialogue
Three commonly used methods in php Tree traversal techniques
Definition and usage of the PHPZip class
The above is the detailed content of PHP uses phpmailer to send emails. For more information, please follow other related articles on the PHP Chinese website!

Thedifferencebetweenunset()andsession_destroy()isthatunset()clearsspecificsessionvariableswhilekeepingthesessionactive,whereassession_destroy()terminatestheentiresession.1)Useunset()toremovespecificsessionvariableswithoutaffectingthesession'soveralls

Stickysessionsensureuserrequestsareroutedtothesameserverforsessiondataconsistency.1)SessionIdentificationassignsuserstoserversusingcookiesorURLmodifications.2)ConsistentRoutingdirectssubsequentrequeststothesameserver.3)LoadBalancingdistributesnewuser

PHPoffersvarioussessionsavehandlers:1)Files:Default,simplebutmaybottleneckonhigh-trafficsites.2)Memcached:High-performance,idealforspeed-criticalapplications.3)Redis:SimilartoMemcached,withaddedpersistence.4)Databases:Offerscontrol,usefulforintegrati

Session in PHP is a mechanism for saving user data on the server side to maintain state between multiple requests. Specifically, 1) the session is started by the session_start() function, and data is stored and read through the $_SESSION super global array; 2) the session data is stored in the server's temporary files by default, but can be optimized through database or memory storage; 3) the session can be used to realize user login status tracking and shopping cart management functions; 4) Pay attention to the secure transmission and performance optimization of the session to ensure the security and efficiency of the application.

PHPsessionsstartwithsession_start(),whichgeneratesauniqueIDandcreatesaserverfile;theypersistacrossrequestsandcanbemanuallyendedwithsession_destroy().1)Sessionsbeginwhensession_start()iscalled,creatingauniqueIDandserverfile.2)Theycontinueasdataisloade

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.


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

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

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

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