Phpmailer is used to send emails (html content, images, and attachments can be sent). phpmailer is a php class used to send emails. it is much better than the built-in function mail in php. phpmailer
Phpmailer is used to send emails (html content, images, and attachments can be sent). phpmailer is a php class used to send emails. it is much better than the built-in function mail in php, phpmailer can be downloaded from the official website.
Here is an example of sending only text:
- */
- Require ("class. phpmailer. php ");
- $ Mail = new phpmailer ();
- $ Mail-> ismail ();
- $ Mail-> addaddress ("email@example.com ");
- $ Mail-> subject = "test 1 ";
- $ Mail-> body = "test 1 of phpmailer .";
- If (! $ Mail-> send ())
- {
- Echo "error sending:". $ mail-> errorinfo ;;
- }
- Else
- {
- Echo "letter sent ";
- }
- /*
- $ Mail-> ismail (); required
- Issendmail-via sendmail command.
- Isqmail-directly via qmail mta.
- Issmtp-via smtp server.
Here is an smtp sample, we assume that this smtp requires authorization. if in't nessesary, only write $ email> smtpauth = 0;, the number of servers to be used uses semicolumn as the separator.
- */
- Require ("class. phpmailer. php ");
- $ Mail = new phpmailer ();
- $ Mail-> issmtp ();
- $ Mail-> host = "smtp1.example.com; smtp2.example.com ";
- $ Mail-> smtpauth = true;
- $ Mail-> username = 'smtpusername ';
- $ Mail-> password = 'smtppassword ';
- $ Mail-> addaddress ("email@example.com ");
- $ Mail-> subject = "test 1 ";
- $ Mail-> body = "test 1 of phpmailer .";
- If (! $ Mail-> send ())
- {
- Echo "error sending:". $ mail-> errorinfo ;;
- }
- Else
- {
- Echo "letter is sent ";
- }
- /*
To add sender inforation, use the following features:
- Mail-> from = "mailer@example.com ";
- $ Mail-> fromname = "my site's mailer ";
- $ Mail-> sender = "mailer@example.com"; // indicates returnpath header
- $ Mail-> addreplyto ("replies@example.com", "replies for my site"); // indicates replyto headers
- For specifying various types of specified ients use these:
- $ Mail-> addaddress ("mail1@domain.com", "your ient 1 ");
- $ Mail-> addcc ("mail1@domain.com", "your ient 1 ");
- $ Mail-> addbcc ("mail1@domain.com", "your ient 1 ");
How to use garbled characters
$ Mail-> charset = "windows-1251"; $ mail-> charset = "UTF-8 ";
Set the encoding. if you want to send an email, you can send an image and add the following code in front of $ mail-send:
- $ Mail-> ishtml (true );
- $ Mail-> addembeddedimage('logo.jpg ', 'logomg', 'logo.jpg '); // attach file logo.jpg, and later link to it using identfier logoimg
- $ Mail-> body = "test 1 of phpmailer html
This is a test picture: "cid: logoimg"/>
";
- $ Mail-> altbody = "this is text only alternative body .";
Send attachment
- $ Mail-> ishtml (false );
- $ Mail-> addattachment ('www .phpfensi.com/invoice-user-1234.pdf', 'invoice.pdf '); // attach files/invoice-user-1234.pdf,
- */