This article mainly introduces PHP email sending cases. Interested friends can refer to it. I hope it will be helpful to everyone.
The role of the mail() function: Connect to the mail server, use the smtp protocol, interact with the server and send mail.
Note:
1. The mail function does not support the esmtp protocol, that is, it can only cast directly and cannot log in.
2. From the above article, we can only send directly to the final receiving server address. And this address is specified in PHP.ini, so we want to use the mail() function to aseoev@ If 163.com sends an email, we need to ---
1) Query the address of the 163 mail server
2) Write the address to php. ini to
php example code is as follows:
SMTP = 163mx02.mxmail.netease.com sendmail_from = wusong@192.168.1.100 var_dump(mail('12345678@qq.com','from php mail function','very intresting'));
But to use the mail function that comes with php to send emails, we need to install one in linux Only sendmail component can be used, otherwise it cannot be used.
If you don’t have this sendmail component, we can use the phpmailer function to operate it. The example code is as follows:
<?php require('./PHPMailer/class.phpmailer.php'); $phpmailer = new PHPMailer(); $phpmailer->IsSMTP(); $phpmailer->Host = 'smtp.163.com'; $phpmailer->SMTPAuth = true; $phpmailer->Username = ''; $phpmailer->Password = ''; $phpmailer->CharSet = 'utf-8'; $phpmailer->From = ''; $phpmailer->FromName = ''; $phpmailer->Subject = ''; $phpmailer->Body = ''; $phpmailer->AddAddress('never_kiss@163.com','Aseoe'); echo $phpmailer->send()?'发送成功':'发送失败'; ?>
There is no content above. Let’s take a look at the code with content. As follows:
<?php /** 用PHPMailer类来发信 步骤: 0: 引入 1: 实例化 2: 配置属性 3: 调用发送 **/ require('./PHPMailer/class.phpmailer.php'); $phpmailer = new PHPMailer(); /* 设置phpmailer发信用的方式 可用用win下mail()函数来发 可以用linux下sendmail,qmail组件来发 可以利用smtp协议登陆到某个账户上,来发 */ $phpmailer->IsSMTP(); // 用smtp协议来发 $phpmailer->Host = 'smtp.163.com'; $phpmailer->SMTPAuth = true; $phpmailer->Username = ''; //发送邮箱的账号(用163邮箱发信的账号) $phpmailer->Password = ''; //发送邮箱的密码 // 可以发信了 $phpmailer->CharSet='utf-8'; $phpmailer->From = 'never_4ill@163.com'; $phpmailer->FromName = 'neverkill'; $phpmailer->Subject = 'Superstart Aseoe'; $phpmailer->Body = '脚本之家(http://www.jb51.net 专注前端开发与编程设计.'; //设置收信人 $phpmailer->AddAddress('never_4ill@163.com','neverkill'); // 添加一个抄送 $phpmailer->AddCC('1234567','Aseoe'); // 发信 echo $phpmailer->send()?'ok':'fail';
Add a method using the above example:
Directly decompress the phpmailer compressed package and put it in the root directory to run, and put the file directly into the local wamp In the root directory, run 02.php to send the email (assuming the php file is executable) - (if not, create a folder in the root directory and repeat the operation) http://localhost/02.php.
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
php uses ffmpeg to implement the method of adding text subtitles to videos
php The definition of parse_str() function and Detailed explanation of usage examples
php method of randomly selecting values from arrays and simple examples
The above is the detailed content of PHP email sending case. For more information, please follow other related articles on the PHP Chinese website!