-
- 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: Ordinary email authentication does not require adding @domain name. This is my 163 email address
- $mail->Password = "password"; // SMTP password Enter the email password here
- $mail->From = "jbxue123@163.com"; // Sender's email address
- $mail->FromName = "Administrator"; // Sender
-
- $ mail->CharSet = "UTF-8"; // Specify the character set here! After specifying UTF-8, the title and sender of the email will not be garbled. If it is GB2312, the title will be garbled.
- $mail->Encoding = "base64";
- $mail->AddAddress($sendto_email,"username" ); // Recipient email and name
- $mail->AddReplyTo("yourmail@yourdomain.com","yourdomain.com");
- //$mail->WordWrap = 50; // set word wrap Number of newline characters
- //$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment attachment
- //$mail->AddAttachment("/tmp/image.jpg", " new.jpg");
- //$mail->IsHTML(true); // send as HTML
- // Email subject
- $mail->Subject = $subject;
- // Email content
- $mail-> ;Body = "hello! PHPMailer";
- //$mail->AltBody ="text/html";
- if(!$mail->Send())
- {
- echo "error
";
- echo "error: " . $mail->ErrorInfo;
- exit;
- }
- else {
- echo "success!";
- }
- }
- // Parameter description (send to, email subject, email content, additional information , username)
- ?>
-
Copy code
Note: When the character set is specified as GB2312, the title will be garbled. If it is specified as UTF-8 here, it will not be garbled.
In fact, PHPMailer also has many functions, such as adding attachments, etc., which will not be demonstrated here.
In this way, you can call this function when you need to use the email function:
-
- require("mail.php");
- smtp_mail("790896688@qq.com", "Welcome to Programmer's Home", "", "", "username") ;
- ?>
Copy code
|