- Require ("phpmailer/class.phpmailer.php");
- function Smtp_mail ($sendto _email, $subject, $body, $extra _hdrs, $user _name) {
- $mail = new Phpmailer ();
- $mail->issmtp (); Send via SMTP
- $mail->host = "smtp.163.com"; SMTP servers
- $mail->smtpauth = true; Turn on SMTP authentication
- $mail->username = "xuchao842363331"; SMTP username Note: Normal mail authentication does not need to add @ domain name here is my 163 mailbox
- $mail->password = "Password"; SMTP Password Enter the password for the mailbox here
- $mail->from = "jbxue123@163.com"; Sender Mailbox
- $mail->fromname = "Administrator"; Sender
- $mail->charset = "UTF-8"; Specify the character set here! After you specify UTF-8, the title and sender of the message will not be garbled, if the GB2312 title will be garbled
- $mail->encoding = "base64";
- $mail->addaddress ($sendto _email, "username"); Recipient's mailbox and name
- $mail->addreplyto ("yourmail@yourdomain.com", "yourdomain.com");
- $mail->wordwrap = 50; Set word wrap word wrapping
- $mail->addattachment ("/var/tmp/file.tar.gz"); Attachment Accessories
- $mail->addattachment ("/tmp/image.jpg", "new.jpg");
- $mail->ishtml (TRUE); Send As HTML
- Message subject
- $mail->subject = $subject;
- Message content
- $mail->body = "hello! Phpmailer ";
- $mail->altbody = "text/html";
- if (! $mail->send ())
- {
- echo "Error
";
- echo "Error:". $mail->errorinfo;
- Exit
- }
- else {
- echo "success!";
- }
- }
- Parameter description (Sent to, message subject, message content, additional information, user name)
- ?>
Copy CodeDescription: When the character set is specified as GB2312, the caption will be garbled, this is specified as UTF-8 does not appear garbled. In fact, Phpmailer also has many functions, such as can add attachments and so on, here is no longer demonstrated. This allows you to call this function when you need to use the Mail function:
- Require ("mail.php");
- Smtp_mail ("790896688@qq.com", "Welcome to the programmer's house", "", "", "username");
- ?>
Copy Code |