PHP uses the Jmail component to send emails

Source: Internet
Author: User
Tags mail account
A friend who has learned asp may know that the jmail component uses a common mailbox sending function in asp. to call the jmail function in php, we need to use the com component for operations. let's first introduce it.

Friends who have learned asp may know that the jmail component uses a common mailbox sending function in asp. to call the jmail function in php, we need to use the com component for operations, let's first introduce the format. the code is as follows:

  1. $ Jmail = new com ("Jmail. Message"); // instantiate a Jmail object
  2. $ Jmail-> SiLent = true; // if it is set to True, Jmail will not prompt the error and only return True and False.
  3. $ Jmail-> LogGing = false; // whether to enable LogGing
  4. $ Jmail-> CharSet = "UTF8"; // sets the string encoding.
  5. $ Jmail-> ContentType = "Text/html"; // The email format is HTML.
  6. $ Jmail-> MailServerUsername = 'Email sending username ';
  7. $ Jmail-> MailServerPassword = 'mail password ';
  8. $ Jmail-> MailServerAddress = 'smtp server address'
  9. $ Jmail-> FromName = 'sender name ';
  10. $ Jmail-> From = 'sender address ';
  11. $ Jmail-> AddRecipient ('recipient address ');
  12. $ Html = 'Email body ';
  13. $ Jmail-> Subject = 'Email title ';
  14. $ Jmail-> Body = $ html;
  15. $ JmailError = $ Jmail-> Send ($ Jmail-> MailServerAddress );
  16. If ($ JmailError) {echo 'sent successfully ';}

The instance code is as follows:

  1. $ Jmail = new COM ('jmail. message') or die ('unable to call the JMail components ');
  2. $ Jmail-> silent = true; // block exception errors
  3. $ Jmail-> charset = 'gb2312'; // Otherwise, Chinese characters will be garbled.
  4. $ Jmail-> From = 'web535000 @ 163.com '; // theoretically, it is not the same as the sender address, but it cannot be used for several attempts using 163.
  5. It can be the same.
  6. $ Jmail-> FromName = 'botest ';
  7. $ Jmail-> AddRecipient ('abc1 @ 163.com '); // you can add multiple email recipients.
  8. // $ Jmail-> AddRecipient ('abc2 @ 163.com ');
  9. // $ Jmail-> AddRecipient ('abc3 @ 163.com ');
  10. $ Jmail-> Subject = 'Email test .';
  11. $ Jmail-> Body = 'This is test email .';
  12. $ Jmail-> MailServerUserName = 'web535000 @ 163.com '; // mail account
  13. $ Jmail-> MailServerPassword = '000000'; // account password
  14. Try {
  15. $ Email = $ jmail-> Send ('smtp .163.com ');
  16. If ($ email) echo 'sent successfully ';
  17. Else echo 'sending failed ';
  18. } Catch (Exception $ e ){
  19. Echo $ e-> getMessage ();
  20. }
  21. ?>

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.