Send mail using Phpmailer

Source: Internet
Author: User

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-&GT;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-&GT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.