Phpmailer sends mail instance code header (& quot; Content-type: texthtml; charsetutf-8 & quot;); include (& amp; 39; phpmailerclassphpmailerphp & amp; 39;); include
Phpmailer email sending instance code
- Header ("Content-type: text/html; charset = utf-8 ");
- Include ('phpmailer/class. phpmailer. php ');
- Include ('phpmailer/class. smtp. php ');
- $ Mail = new PHPMailer ();
- $ Mail-> IsSMTP (); // set mailer to use SMTP
- $ Mail-> Host = "smtp.sohu.com"; // SMTP server
- $ Mail-> Port = 25;
- $ Mail-> SMTPAuth = true; // SMTP Authentication?
- $ Mail-> Username = "yourmail@sohu.com"; // User name
- $ Mail-> Password = "yourmail168"; // Password
- $ Mail-> From = "spr_zsql@163.com"; // sender address
- $ Mail-> FromName = "test"; // sender
- $ Mail-> AddAddress ("yourmail@qq.com", "test"); // recipient address, recipient name
- $ Mail-> WordWrap = 50;
- // $ Mail-> AddAttachment ("/var/tmp/file.tar.gz"); // attachment
- // $ Mail-> AddAttachment ("/tmp/image.jpg", "new.jpg"); // attachment, new file name
- $ Mail-> IsHTML (true); // HTML format
- $ Mail-> Subject = "test ";
- $ Mail-> Body = "test ";
- If (! $ Mail-> Send ())
- {
- Echo "Mailer Error:". $ mail-> ErrorInfo;
- Echo "an error occurred while sending the email! ";
- } Else {
- Echo "email sent successfully! ";
- }