-
- 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 = "200.162.244.66"; // SMTP servers
- $mail->SMTPAuth = true; // turn on SMTP authentication
- $mail->Username = "yourmail"; // SMTP username Note: Ordinary email authentication does not require adding @domain name
- $mail->Password = "mailPassword"; // SMTP password
- $mail->From = "yourmail@yourdomain.com"; // Sender's email
- $mail->FromName = "Administrator"; // Sender
-
- $mail->CharSet = "GB2312"; // Specify here character set!
- $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
- //$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 = "
-
-
-
-
-
- I love php
-
-
- ";
- $mail->AltBody ="text/html";
- if(!$mail->Send())
- {
- echo "Send email Error
";
- echo "Mail error message: " . $mail->ErrorInfo;
- exit;
- }
- else {
- echo "$user_name Email sent successfully!
";
- }
- }
- // Parameter description (send to, email subject, email content, additional information, user name)
- smtp_mail("yourmail@yourdomain.com", "Welcome to phpmailer! ", "NULL", "yourdomain.com", "username");
- ?>
Copy code
Note:
1. Email character set setting, $mail->CharSet = "GB2312"; // Specify the character set here! Here I only specify GB2312 because this way Outlook can display the email subject normally. I have tried setting it to utf-8 but it displays garbled characters in Outlook.
2. If you are sending emails in html format, remember to also specify
3. If you want to use it to send mass emails, remember to modify the include file function, such as:
require("phpmailer/class.phpmailer.php");
Change to
require_once("phpmailer/class.phpmailer.php");
Otherwise, class redefinition will occur.
Personally, I think that to use phpmailer, first of all, you need to have a mail server. PHP's mail function is not specified. It should be the SMTP set by PHP.
Here you need to specify it specifically, and you also need to specify the administrator and password of the mail server.
|