Install SendMail and modify php.ini on the server

Source: Internet
Author: User

Installing SendMail on the server

sudo apt-get install SendMail

Start SendMail

Sudo/etc/init.d/sendmail start

Modify PHP.ini

[Mail function]  
SMTP = localhost  
smtp_port =  
Sendmail_from = me@example.com

Function SendMail

<?php/* Call Phpmailer send e-mail * @param string $receiver recipient * @param string $sender sender * @param string $sender _name The sender's name if NULL, replace * @param string $subject Message subject * @param string $content message content * @param b Oolean $ishtml HTML Email * See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/PHP/* @param Array $at  Tachements Annex * @return Boolean/function SendMail ($receiver, $sender, $sender _name, $subject, $content, $ishtml =true,   
      
    $attachments =array ()) {include_once "class-phpmailer.php";  
    if (Empty ($receiver) | | | empty ($sender) | | | | empty ($subject) | | empty ($content)) {return false;    
      
    } $mail = new Phpmailer ();                $mail->issmtp (); Sent via SMTP//$mail->host = "smtp.gmail.com";              SMTP Server//$mail->port = 465;      SMTP Port//$mail->smtpsecure = ' SSL ';         Encryption mode//$mail->smtpauth = true; Turn on SMTP authentication 
    $mail->username = "Username";   Username//$mail->password = "Password";                  Password $mail->ismail ();            The Using PHP mail () function may show that the email may not be prompted by the following user $mail->from = $sender;   The sender $mail->fromname = $sender _name;       The sender alias $mail->addreplyto ($sender);     $mail->addaddress ($receiver) of the person who replied;  
    The addressee//sends the IF ($ishtml) {$mail->ishtml (true) in HTML; //Send attachment if ($attachments) {if (Is_array ($attachments)) {$send _attachments = arr  
      
            Ay ();  
            $tmp _attachments = array_slice ($attachments, 0, 1); if (!is_array (Array_pop ($tmp _attachments))) {if (Isset ($attachments [' path '])) {array                      
                _push ($send _attachments, $attachments);  
 }else{foreach ($attachments as $attachment) {                       Array_push ($send _attachments, Array (' path ' => $attachment));  
            }}else{$send _attachments = $attachments; foreach ($send _attachments as $attachment) {$attachment [' name '] = Isset ($attachmen t[' name '])?  
                $attachment [' name ']: null; $attachment [' encoding '] = isset ($attachment [' Encoding '])?  
                $attachment [' Encoding ']: ' base64 '; $attachment [' type '] = isset ($attachment [' type '])?  
                $attachment [' type ']: ' Application/octet-stream '; if (Isset ($attachment [' path ']) && file_exists ($attachment [' Path '])} {$mail->addattachment (  
                $attachment [' Path '], $attachment [' name '], $attachment [' Encoding '], $attachment [' type ']);  
                }}}elseif (Is_string ($attachments)) {if (file_exists ($attachments)) { $mail->addattachment($attachments);  }}} $mail->subject = $subject;  Mail title $mail->body = $content;    
Mail content return $mail->send ();  
}//DEMO $receiver = ' receiver@test.com ';  
$sender = ' sender@test.com ';  
$sender _name = ' sender name ';  
$subject = ' Subjecct ';  
      
$content = ' content ';  
All four formats can be $attachments = ' attachment1.jpg ';  
$attachments = Array (' path ' => ' attachment1.jpg ', ' name ' => ' annex 1.jpg ');  
$attachments = Array (' attachment1.jpg ', ' attachment2.jpg ', ' attachment3.jpg '); $attachments = Array (' path ' => ' attachment1.jpg ', ' name ' => ' Attachment 1.jpg '), Array (' Path ' => ' Attachment2  
      
. jpg ', ' name ' => ' annex 2.jpg '), Array (' Path ' => ' attachment3.jpg ', ' name ' => ' annex 3.jpg '),);  
$flag = SendMail ($receiver, $sender, $sender _name, $subject, $content, True, $attachments);  
      
Echo $flag; ?>

Source Address: http://download.csdn.net/detail/fdipzone/5151095

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.