| The code is as follows |
Copy Code |
<?php
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 = "xuchao842363331@163.com"; Sender's mailbox
$mail->fromname = "Administrator"; Sender
$mail->charset = "UTF-8"; This specifies the character set! Specify UTF-8 after the message title and sender and so will not garbled, if it is GB2312 title will be garbled
$mail->encoding = "base64";
$mail->addaddress ($sendto _email, "username"); Recipient mailboxes and Names
$mail->addreplyto ("yourmail@yourdomain.com", "yourdomain.com");
$mail->wordwrap = 50; Set word wrap line-wrapping words
$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 <p>";
echo "Error:". $mail->errorinfo;
Exit
}
else {
echo "success!";
}
}
Parameter description (send to, mail subject, message content, additional information, user name)
?> |
To explain: When the character set is designated as GB2312 when the title will be garbled, here specified as UTF-8 will not appear garbled.
In fact, Phpmailer also has many functions, such as the ability to 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:
| The code is as follows |
Copy Code |
<?php
Require ("mail.php");
Smtp_mail ("842363331@qq.com", "Reminders", "" "," "," username ");
?> |