The example of this article describes the Phpmailer usage of the PHP mail sending class, and details its detailed operation steps. Share to everyone for your reference. The specific steps are as follows:
1. Install SendMail on the server
sudo apt-get install SendMail
2. Start SendMail
Sudo/etc/init.d/sendmail start
3. Modify PHP.ini
[Mail function]
SMTP = localhost
smtp_port =
Sendmail_from = me@example.com
The 4.Function SendMail function is as follows
<?php/* Call Phpmailer send e-mail * @param string $receiver recipient * @param string $sender sender * @param string $sender _na Me sender name if empty, replace * @param string $subject Message subject * @param string $content message content * @param boolean $ishtml whether HTML E-mail * @param Array $attachements Attachment * @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; Open SMTP Authentication//$mail->username = "Username"; Username//$mail->password = "Password"; Password $mail->ismail (); Using PHP mail () function may appear this email may not be the following$mail->from = $sender of the prompts sent by the user; 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 = array ();
$tmp _attachments = array_slice ($attachments, 0, 1); if (!is_array (Array_pop ($tmp _attachments))) {if (Isset ($attachments [' path '])) {Array_push ($send _attachme
NTS, $attachments); }else{foreach ($attachments as $attachment) {Array_push ($send _attachments, Array (' Path ' => $attac
Hment));
}}else{$send _attachments = $attachments; foreach ($send _attachments as $attachment) {$attachment [' name '] = isset ($attachment [' name '])? $attachme
nt[' 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 examples are as follows: $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 Click here to download the site.
I hope this article will help you with the learning of PHP programming.