Home>Article>Daily Programming> PHP implements sending emails (4)
In the previous article "PHP Implementation of Sending Emails (3)", we gave you a brief introduction to the method library through PHPMailer To achieve the functional effect of sending emails. Next, we will continue to explain how to implement the specific function of sending emails through PHPMailer based on the content of the previous article.
email.php code is as follows:
isSMTP(); //smtp需要鉴权 这个必须是true $mail->SMTPAuth = true; // qq 邮箱的 smtp服务器地址,这里当然也可以写其他的 smtp服务器地址 $mail->Host = 'smtp.qq.com'; //smtp登录的账号 这里填入字符串格式的qq号即可 $mail->Username = '244103592@qq.com'; // 这个就是之前得到的授权码,一共16位 $mail->Password = 'hlclkdigsqqdbged'; $mail->setFrom('244103592@qq.com', 'send_user_name'); // $to 为收件人的邮箱地址,如果想一次性发送向多个邮箱地址,则只需要将下面这个方法多次调用即可 $mail->addAddress($to); // 该邮件的主题 $mail->Subject = $title; // 该邮件的正文内容 $mail->Body = $content; // 使用 send() 方法发送邮件 if(!$mail->send()) { return '发送失败: ' . $mail->ErrorInfo; } else { return "发送成功"; } } // 调用发送方法,并在页面上输出发送邮件的状态 var_dump(sendMail('2286445505@qq.com','会议主题','今天下午开会'));
PHPMailer method library download address://m.sbmmt.com/ xiazai/learn/5627
In the above codesendMailmethod, after introducing PHPMailerAutoload.phpand instantiatingPHPMailer, Related function methods can be called.
$mail->isSMTP()means using SMTP service;
$mail->SMTPAuthsets whether to use authentication ( Must be true);
$mail->HostSet the sender’sSMTP server address;
##$mail-> ;UsernameSet the sender's qq mailbox username;
$mail->PasswordSet the sender's mailbox password. Note that when using qq mailbox, fill in the "authorization password" "Instead of the email login password! (For the method of obtaining the qq authorization code, please refer to the article "PHP Implementation of Sending Mail (1)")
$mail->setFrom()is used to set the sender Information, such as the sender in the email format description, will be displayed here as send_user_name (xxxx@qq.com), and send_user_name is displayed as the name.
$mail->addAddress()Used to set the recipient’s email address.
$mail->SubjectSet the email title;
$mail->BodySet the email body.
The above is the detailed content of PHP implements sending emails (4). For more information, please follow other related articles on the PHP Chinese website!