Home  >  Article  >  Backend Development  >  What should I do if php uses SMTP to send garbled emails?

What should I do if php uses SMTP to send garbled emails?

coldplay.xixi
coldplay.xixiOriginal
2020-08-03 11:27:372864browse

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.

What should I do if php uses SMTP to send garbled emails?

Solution to php using SMTP to send garbled emails:

Here we use an encapsulated The smtpclassemail.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 (&#39;email.class.php&#39;);
$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!

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