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.
The following shows an example of sending only text.
*/
The code is as follows: |
Copy code |
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. Let's assume that the smtp needs authorization. If in't nessesary, write only $ email> smtpauth = 0 ;. The number of servers to be used uses the semicolumn 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 functions:
The code is as follows: |
Copy code |
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 encoding
If you want to send an email, you can send an image and add the following html code before $ mail-send ().
The code is as follows: |
Copy code |
$ Mail-> ishtml (true ); $ Mail-> addembeddedimage('logo.jpg ', 'logomg', 'logo.jpg '); // attach file logo.jpg, and later link to it using identfier logoimg $ Mail-> body = "<P> this is a test picture: </p> "; $ Mail-> altbody = "this is text only alternative body ."; |
Send attachment
The code is as follows: |
Copy code |
$ Mail-> ishtml (false ); $ Mail-> addattachment ('www .111cn.net/invoice-user-1234.pdf', 'invoice.pdf '); // attach files/invoice-user-1234.pdf, |
*/