The solution to php using SMTP to send garbled emails: first introduce [email.class.php]; then instantiate the smtp class and configure the debug mode; finally send the email. Note that you need to set the encoding at the end. That’s it.
Solution to php using SMTP to send garbled emails:
Here we use an encapsulated The smtp
classemail.class.php
class has been modified by me and the encoding settings have been added. Without the encoding settings, garbled characters will appear on some clients that cannot automatically recognize the encoding.
About the use of this class:
<?php require_once ('email.class.php'); $smtpserver = "smtp.exmail.qq.com"; $smtpserverport =25; $smtpusermail = "lyushine@qq.com"; $smtpuser = "lyushine@qq.com"; $smtppass = "xxxxxx"; $mailtype = "HTML"; $smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass); $smtp->debug = false; $smtp->sendmail($to, $smtpusermail, $subject,$message, $mailtype,"utf-8"); ?>
You can probably understand it by looking at the above code. First introduce email.class.php and then instantiate the smtp class, configure the debug mode, and send the email. What you need to pay attention to is setting the final encoding.
Related learning recommendations: PHP programming from entry to proficiency
The above is the detailed content of What should I do if php uses SMTP to send garbled emails?. For more information, please follow other related articles on the PHP Chinese website!