Share a PHP Mail library--swiftmailer

Source: Internet
Author: User
Recently saw a good PHP mail library, like Phpmailer role, but performance than Phpmailer, especially in the ability to handle attachments, send mail success is also high. Here is a description of the usage:

1require_once("lib/swift_required.php");23//Create a Transport object, set the mail server and port number, and set the user name and password for authentication4$transport= Swift_smtptransport::newinstance (' smtp.163.com ', 25)5->setusername (' username@163.com ')6->setpassword (' Password ');78//Create a Mailer object9$mailer= Swift_mailer::newinstance ($transport);Ten One//Create a Message object A$message= Swift_message::newinstance (); - -//Set Message subject the$message->setsubject (' This is a test email ') - -//to set the message content, you can omit Content-type --Setbody ( +'' . -'' . +'' . A' Here's an image//Embedded Files at$message->embed (Swift_image::frompath (' image.jpg ')). -' alt= ' share a PHP mail library--swiftmailer "/>". -' Rest of message '. -' Baidu '. -'' . -'', in' Text/html ' -); to +//create Attachment object, Content-type This parameter can be omitted -$attachment= Swift_attachment::frompath (' image.jpg ', ' image/jpeg ') the->setfilename (' cool.jpg '); * $//Add an attachmentPanax Notoginseng$message->attach ($attachment); - the//set the recipient address with an associative array, you can set multiple recipients +$message->setto (Array(' to@qq.com ' = ' toname ')); A the//set the sender's address with an associative array, you can set up more than one sender +$message->setfrom (Array( -' from@163.com ' = ' fromname ', $)); $ -//Add cc person -$message->SETCC (Array( the' Cc@qq.com ' = ' Cc ' - ));Wuyi the//add encryption to send people -$message->SETBCC (Array( Wu' Bcc@qq.com ' = ' Bcc ' -)); About $//set up message receipts -$message->setreadreceiptto (' receipt@163.com '); - -//Send mail A$result=$mailer->send ($message);

The above describes the sharing of a PHP mail library--swiftmailer, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.