First download the phpmailer-master, then we unzip it. Get the following file.
Put the file in the PHP environment, after the new email.php in the root directory, the code is as follows:
<?PHPHeader(' content-type:text/html; Charset=utf-8 '); require'./phpmailerautoload.php '; $mail=NewPhpmailer; $mail->ISSMTP ();//set up mail using SMTP$mail->host = ' smtp.163.com ';//Mail server address$mail->smtpauth =true;//Enable SMTP authentication$mail->charset = "UTF-8";//set up message encoding$mail->setlanguage (' zh_cn ');//set error Chinese tips$mail->username = ' [email protected] ';//SMTP user name, which is the personal email address$mail->password = ' ******** ';//SMTP Password, which is the personal mailbox password$mail->smtpsecure = ' TLS ';//set enable encryption, note: The Php_openssl module must be turned on$mail->priority = 3;//Set Message Priority 1: High, 3: normal (Default), 5: Low$mail->from = ' [email protected] ';//Sender e-mail address$mail->fromname = ' Wang Jia Yi ';//Sender Name$mail->addaddress (Htmlspecialchars($_post[' addressee ']);//Add Recipient/*$mail->addaddress (' [email protected] '); Add multiple Recipients $mail->addreplyto (' [email protected] ', ' information '); */ //Add a reply to a person$mail->ADDCC (Htmlspecialchars($_post[' Chaosong ']);//Add cc person/*$mail->ADDCC (' [email protected] '); */ //add multiple cc people$mail->confirmreadingto = ' [email protected] ';//Add a Send receipt e-mail address, that is, when the recipient opens the message, asks if receipts have occurred/*$mail->addbcc (' [email protected] '); */ //Add encrypted send, Mail header will not display the secret send the person information$mail-WordWrap= 50;//set 50 characters for line wrapping$mail->addattachment ($_files["File"] ["name"]);//Add an attachment/*$mail->addattachment ('/tmp/image.jpg ', ' one pic ');*/ //Add multiple attachments$mail->ishtml (true);//set the message format to HTML$mail->subject =Htmlspecialchars($_post[' title ']);$mail->body =Htmlspecialchars($_post[' remarks ']);//HTML version$mail->altbody = ' txt ';//txt versionif(!$mail-Send ()) { Echo' Message could not being sent. '; Echo' Mailer Error: '.$mail-errorinfo; Exit;}Echo' Sent successfully! ‘;?>
It is important to note that the SMTP password is usually the mailbox password that you send the mailbox to, but it may also be a separate password that is set up specifically for SMTP.
Also in the root directory we create a new index.html/php to be responsible for the email.php value, the code is as follows:
<HTML><Head> <title>Edit Message</title></Head><Body><formAction= "email.php"Method= "POST"enctype= "Multipart/form-data">Send to:<inputtype= "text"name= "Addressee" /><BR/>Topics:<inputtype= "text"name= "title" /><BR/>cc:<inputtype= "text"name= "Chaosong" /><BR/>Upload attachments:<inputtype= "File"name= "File"ID= "File" /><BR/>remark:<textareaname= "Remarks"cols= " the"rows= "3"></textarea><BR/> <inputname= "Submit"type= "Submit" /><BR/></form></Body></HTML>
The value in the form is consistent with the back-end email receive value, and the pro-test is effective.
Send mail using Phpmailer