Home > Article > Backend Development > Example of sending emails using PHPMailer mail class (163 mailbox)
Let me introduce you to an example of sending emails with PHPMailer, using smtp.163.com as the smtp when sending. Friends in need can refer to it.
1. Download the PHPMailer file package, PHPMailer email sending class V5.1 download address. 2. Confirm that the server supports sockets and check whether sockets are supported. Note: socket is a PHP extension, and a configuration option for ./configure --enable-sockets must be given when compiling. 3. Unzip the file to your web server directory and call the class. Description: First include class.phpmailer.php, then create the object, set parameters, and call member functions. The code is as follows: IsSMTP(); // send via SMTP $mail->Host = "200.162.244.66"; // SMTP servers $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = "yourmail"; // SMTP username 注意:普通邮件认证不需要加 @域名 $mail->Password = "mailPassword"; // SMTP password $mail->From = "yourmail@jbxue.com"; // 发件人邮箱 $mail->FromName = "jbxue.com管理员"; // 发件人 $mail->CharSet = "GB2312"; // 这里指定字符集! $mail->Encoding = "base64"; $mail->AddAddress($sendto_email,"username"); // 收件人邮箱和姓名 $mail->AddReplyTo("yourmail@jbxue.com","jbxue.com"); //$mail->WordWrap = 50; // set word wrap //$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment //$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); $mail->IsHTML(true); // send as HTML // 邮件主题 $mail->Subject = $subject; // 邮件内容 $mail->Body = ' 欢迎来到http://bbs.it-home.org Note: 1. Mail character set setting, $mail->CharSet = "GB2312"; // Specify the character set! I only specify GB2312 here because this way Outlook can display the email subject normally. I tried setting it to utf-8, but it showed garbled characters in Outlook. 2. Send emails in html format, remember to specify 3. When sending mass emails, remember to modify the included file function, such as: require("phpmailer/class.phpmailer.php"); Change to require_once("phpmailer/class.phpmailer.php"); Otherwise, you will be prompted to redefine the class. |