: This article mainly introduces a php email Library-swiftmailer. if you are interested in the PHP Tutorial, refer to it. Recently, I saw a good php mail library, which works the same as phpmailer, but has better performance than phpmailer. especially in terms of the ability to process attachments, the chances of sending emails are high. The following describes the usage:
1require_once ("lib/swift_required.php"); 2 3 // create a Transport object, set the email server and port number, and set the user name and password for verification 4 $ transport = Swift_SmtpTransport :: newInstance ('smtp .163.com ', 25) 5-> setUsername ('username @ 163.com') 6-> setPassword ('password '); 7 8 // create mailer object 9 $ mailer = Swift_Mailer: newInstance ($ transport); 1011 // Create message object 12 $ message = Swift_Message: newInstance (); 1314 // Set the Mail subject 15 $ message-> setSubject ('This is a test mail') 1617 // Set the Mail content, which can omit the content-type18-> setBody (19''. 20''. 21''. 22 'Here is an image // embedded file 23 $ message-> embed (Swift_Image: fromPath('image.jpg ')). 24 '"alt =" share a php email library -- swiftmailer "/> '. 25 'rest of message '. 26 'Baidu '. 27''. 28'', 29' text/html '30); 3132 // Create an attachment object. the content-type parameter can be omitted 33 $ attachment = Swift_Attachment: fromPath('image.jpg ', 'image/jpeg ') 34-> setFilename('cool.jpg'); 3536 // add an attachment 37 $ message-> attach ($ attachment); 3839 // Set the recipient address with an associated array, you can set multiple recipients: 40 $ message-> setTo (array ('to @ qq.com '=> 'toname'); 4142 // you can set the sender address with an associated array, you can set multiple senders 43 $ message-> setFrom (array (44 'from @ 163.com '=> 'fromname', 45 )); 4647 // add Cc to 48 $ message-> setCc (array (49 'CC @ qq.com '=> 'CC' 50 )); 5152 // add Bcc 53 $ message-> setBcc (array (54 'bcc @ qq.com '=> 'bcc' 55 )); 5657 // Set the email receipt 58 $ message-> setreadreceip ('receipt @ 163.com '); 5960 // send email 61 $ result = $ mailer-> send ($ message );
The above introduces a php email Library-swiftmailer, which includes some content and hopes to help those who are interested in PHP tutorials.