installing SendMail on the server
sudo apt-get install SendMail
Start SendMail
Sudo/etc/init.d/sendmail start
Modify PHP.ini
[Mail Function] SMTP = Localhostsmtp_port = 25sendmail_from = me@example.com
Function SendMail
<?php/* call Phpmailer Send email * @param string $receiver recipient * @param string $sender sender * @param string $sender _ Name if empty the sender address instead of * @param string $subject Message subject * @param string $content message content * @param boolean $ishtml HTML email * @param Array $attachements attachment * @return boolean*/function sendMail ($receiver, $sender, $sender _name, $sub Ject, $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; Open SMTP Authentication//$mail->username = "Username"; Username//$mail->password = "Password"; Password $mail->ismail (); Using PHP mail () function may appear that this email may not be a hint sent by the following user $mail->from = $sender; Sender $mail->fromname = $sender _name; Sender alias $mail->addreplyto ($sender); Reply Person $mail->addaddress ($receiver); Recipient//HTML send if ($ishtml) {$mail->ishtml (true);} Send attachment if ($attachments) {if (Is_array ($attachments)) {$send _attachments = array (); $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 ($attachment [' 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 header $mail->body = $content;//message content return $mail->send (); }//demo$receiver = ' receiver@test.com '; $sender = ' sender@test.com '; $sender _name = ' sender name '; $subject = ' Subjecct '; $ Content = ' content ';//Four formats can be $attachments = ' attachment1.jpg '; $attachments = array (' path ' = ' attachment1.jpg ', ' Name ' = = ' attachment 1.jpg '); $attachments = Array (' attachment1.jpg ', ' attachment2.jpg ', ' attachment3.jpg '); $attachments = Array (' path ' = ' attachment1.jpg ', ' name ' = = ' attachment 1.jpg '), Array (' path ' = ' attachment2.jpg ', ' name ' = ' = ') Attachment 2.jpg '), Array (' path ' = ' attachment3.jpg ', ' name ' = ' = ' attachment 3.jpg '), $flag = SendMail ($receiver, $sender, $sender _ Name, $subject, $content, True, $attachments); Echo $flag;? >
The above is phpmailer-php email transport class content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!