XAMPP and thinkphp build a local station and send mail

Source: Internet
Author: User
Tags server port

I. Installation and use of XAMPP

1. First look at what is XAMPP, want to build a small partner must know, XAMPP (Apache+mysql+php+perl) is a powerful building XAMPP software station integration package.

It can be installed in Windows, Linux, Solaris, Mac os X and many other operating systems

2. What version do I need to download to official website:xampp Download

3. Installation is very simple, stupid installation, feel the MySQL option can be removed, install one yourself, the specific installation look at this:MySQL installation , the other path is recommended only to change the drive letter, the suffix path is reserved

4. The installed directory is as follows

5. Find Xampp-contorller.exe Open, turn Apache on, enter: LOCALHOST/XAMPP, have content appears to indicate success, if not successful, the default port 80 that Apache occupies is occupied by other programs,

You can change the port 80 to another port under httpd.conf under Xampp/apache/conf, such as 81. Then enter the LOCALHOST:81/XAMPP on the browser and try again, and then change the port until you can.

6. To this PHP running environment has been completed, the following can download a thinkphp framework can be built on the local site.

Two. Use of the thinkphp framework

1.thinkphp is a PHP domestic framework, very useful, this is the official website:thinkphp official website , download the latest version of the framework from here

2. Under the XAMPP under the Htdocs file to create a file, name your site to use the name, and then the download thinkphp framework extracted to the file, after the effect of decompression as follows:

3. You can download a Sublimetext code editor to open the project you built, for example, I built an email: access to Localhost/email, this time will automatically generate an MVC framework. As follows

4. Here a running site has been formed, specifically to write a small example can see the thinkphp off the net of the tutorial, the following introduction of the next message to send a small program wording

Third, write a mail sent by the Web program

Where the code in Indexcontroller is:

Public Function Index () {//Display send mail page
$this->name = ' mail sending system '; Assigning a template variable
$this->display ();
}

Public function Send () {//post request, send message
$mail =i (' Post.mail ');
$service =d (' Index ', ' service ');
$result = $service->sendmail ($mail);
if ($result = = True) {
$this->success ("sent successfully");
}
$this->error ($result);
}

This is the HTML code under view:



<title>{$name}</title>

<body>

<form method= "POST" action= "{: U (' Index/send ')}" >
<input type= "text" name= "Mail"/>
<input type= "Submit" value= "Send"/>
</form>
</body>

The following is the code in the service, the main record function in Indexservice operation:

Class indexservice{
public $ResultData;//A variable that is not used to define

Public Function SendMail ($mail) {//Send mail
$title = "Mail sending test";
$path = App_path. ' Home/mailtemp/mail.html ';//Here's what you're going to send.
$body = file_get_contents ($path);
$body = Str_replace ("{u}", "<a href= ' http://hao123.com ' > Navigation site </a>", $body);
$body = Str_replace ("{T}", Date (' y-m-d h:i:s '), $body);
Return Send_mail ($mail, $mail, $title, $body);//This is in the public function, which is the function, which can be called directly
}

The following is the code in function.php:

function Send_mail ($to, $name, $subject = ", $body =", $attachment = null, $config = ") {
$config = Is_array ($config)? $config: C (' system_email ');//This is the configuration configured in Config under Conmmon
Import (' Phpmailer ', Think_path. Library/org/net/mail ', '. class.php ');//In this path there is a PHP API to send mail, if the framework is not able to download a
$mail = new Phpmailer (); Phpmailer Object

$mail->charset = ' UTF-8 ';//Set the message encoding, default iso-8859-1, if the Chinese this item must be set, otherwise garbled
$mail->issmtp ();//set to use the SMTP service
$mail->ishtml (true);
$mail->smtpdebug = 0;//Turn Off the SMTP debugging feature 1 = errors and Messages2 = Messages only
$mail->smtpauth = true;//enable SMTP authentication feature
if ($config [' smtp_port '] = = 465)
$mail->smtpsecure = ' SSL ';//Use Security protocol
$mail->host = $config [' smtp_host '];//SMTP Server
$mail->port = $config [' smtp_port '];//port number of the SMTP server
$mail->username = $config [' Smtp_user '];//SMTP Server user name
$mail->password = $config [' Smtp_pass '];//SMTP Server password
$mail->setfrom ($config [' From_email '], $config [' from_name ']);
$replyEmail = $config [' Reply_email ']? $config [' Reply_email ']: $config [' reply_email '];
$replyName = $config [' Reply_name ']? $config [' Reply_name ']: $config [' reply_name '];
$mail->addreplyto ($replyEmail, $replyName);
$mail->subject = $subject;
$mail->msghtml ($body);
$mail->addaddress ($to, $name);
if (Is_array ($attachment)) {//Add attachment
foreach ($attachment as $file) {;
if (Is_array ($file)) {
is_file ($file [' path ']) && $mail->addattachment ($file [' Path '], $file [' name ']);
} else {
is_file ($file) && $mail->addattachment ($file);
}
}
} else {
is_file ($attachment) && $mail->addattachment ($attachment);
}
$result = $mail->send ();
return $result? True: $mail->errorinfo;
}

Here is the code below the config:

<?php
return Array (
//' config item ' = ' config value '
//Mail configuration
' system_email ' = Array (
' smtp_host ' = ' smtp.163.com ',//SMTP server
' smtp_port ' + ',//SMTP server port
' smtp_user ' = ' [email protected] ',//SMTP server username//fill in your username
' smtp_pass ' = ', '//SMTP server password//password of your own mailbox
' from_email ' = ' [email protected] ',//Sender Email
' from_name ' = ' marin ',//sender name
' reply_email ' + ',//reply to email (left blank for sender email)
' reply_name ' + ', '//reply name (left blank is the sender's name)
),
);

Here are the following:

Below is I provide the source connection, the file is extracted directly into the XAMPP under the htdocs can be, ps: Mail configuration changed to their own on the line

Download connection of Baidu cloud disk

XAMPP and thinkphp build a local station and send mail

Related Article

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.