Phpmailer Send mail Instance program

Source: Internet
Author: User
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 ");

?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.