Home > Backend Development > PHP Tutorial > PHPMailer mail class uses smtp.163.com to send mail method_PHP tutorial

PHPMailer mail class uses smtp.163.com to send mail method_PHP tutorial

WBOY
Release: 2016-07-21 15:50:18
Original
1726 people have browsed it

Step 1: You need to download the PHPMailer file package phpmailer-1.73.tar.gz from the open source community: http://phpmailer.sourceforge.net/
Step 2: Confirm that your server system supports sockets, as shown below, through phpinfo (); Check whether sockets are supported
If this item is not available, please note: socket is a PHP extension, and a configuration option for ./configure --enable-sockets must be given when compiling.
PHPMailer mail class uses smtp.163.com to send mail method_PHP tutorial
Step 3: Unzip the file to your web server directory and call the class. Instructions: First include class.phpmailer.php, then create the object, set parameters, and call member functions . For details, please see the sample code below:

Copy code The code is as follows:

/** *****************************
* Author: Li Yingjiang
* Date: 2006-12-7
*****************************/
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@cgsir.com"; // Sender's email address
$mail->FromName = "cgsir.com management Member"; // Sender

$mail->CharSet = "GB2312"; // Specify the character set here!
$mail->Encoding = "base64";

$mail->AddAddress($sendto_email,"username"); // Recipient email and name
$mail-> ;AddReplyTo("yourmail@cgsir.com","cgsir.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
// Email subject
$mail->Subject = $subject;
// Email content
$mail-> Body = '




Welcome tohttp://www.cgsir.com


Thank you for registering as a member of this site!




';

$mail->AltBody ="text/html ";
if(!$mail->Send())
{
echo "The email was sent in error

";
echo "Email 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@cgsir.com', 'Welcome to cgsir.com!', 'NULL', 'cgsir .com', 'username');

?>

Things to note:
 1. Character set setting of the email, $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 an email in html format, remember to also specify

3. If you want to use it to send 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, class redefinition will occur.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319386.htmlTechArticleStep 1: You need to download the PHPMailer file package phpmailer-1.73.tar.gz from the open source community: http:// phpmailer.sourceforge.net/ Step 2: Confirm that your server system supports socket, as shown below...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template