Share a php email Library-swiftmailer

Source: Internet
Author: User
Tags php email
: 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.