thinkphp Mail Send Class

Source: Internet
Author: User

Recently in a project, need to have the function of sending mail, server mail, the server must have the ability to link mail server, in order to achieve the following steps, now to share with you, dedicated to send a message class

/** * System mail Send function * @param string $to recipient mailbox * @param string $name Recipient name * @param string $subject message subject * @param String $body Message content * @param string $attachment Attachment list * @return Boolean/function Think_send_mail ($to, $name, $subje
    ct = ', $body = ', $attachment = null) {$config = C (' Think_email '); Vendor (' Phpmailer.class#phpmailer '); Guide class.phpmailer.php class file from Phpmailer directory $mail = new Phpmailer (); Phpmailer object $mail->charset = ' UTF-8 ';  Set message encoding, default iso-8859-1, if the Chinese must be set up, otherwise garbled $mail->issmtp ();                     Set up to use SMTP service $mail->smtpdebug = 0;
                                               Turn off the SMTP debugging feature//1 = errors and messages                  2 = messages only $mail->smtpauth = true;                 Enable the SMTP authentication feature $mail->smtpsecure = ' SSL ';  Use security protocol $mail->host = $config [' Smtp_host ']; SMTP server $mail->port = $config [' SMTP_port '];  The port number of the SMTP server $mail->username = $config [' Smtp_user '];  SMTP Server user name $mail->password = $config [' Smtp_pass '];
    SMTP server password $mail->setfrom ($config [' From_email '], $config [' from_name ']);
    $replyEmail = $config [' Reply_email ']? $config [' Reply_email ']: $config [' from_email '];
    $replyName = $config [' Reply_name ']? $config [' Reply_name ']: $config [' from_name '];
    $mail->addreplyto ($replyEmail, $replyName);
    $mail->subject = $subject;
    $mail->msghtml ($body);
    $mail->addaddress ($to, $name); if (Is_array ($attachment)) {//Add attachment foreach ($attachment as $file) {is_file ($file) && $mail ;
        AddAttachment ($file); } return $mail->send ()?
 true: $mail->errorinfo; }

This function can only be used in thinkphp and requires phpmailer extended support;

The Phpmailer extension's placement directory is thinkphp/extend/vendor/phpmailer/class.phpmailer.php

Phpmail's Download Address:

Https://code.google.com/a/apache-extras.org/p/phpmailer

Use this function to include the following configuration items in your project

Mail configuration
 ' think_email ' => array (
    ' smtp_host '   => ' smtp.aaa.com ',//smtp server
    ' smtp_port '   = > ' 465 ',//SMTP server port
    ' smtp_user '   => ' mail@aaa.com ',//SMTP server username
    ' smtp_pass   ' => ' password ' ,//SMTP server password
    ' from_email '  => ' mail@aaa.com ',//Sender email ' from_name ' => ' thinkphp '   ,// Sender name
    ' reply_email ' => ',//reply email (leave blank for sender email)
    ' reply_name '  => ',//reply name (leave blank for sender name)
 ),

This article is from the "尛 lei" blog, please be sure to keep this source http://a3147972.blog.51cto.com/2366547/1221287

See more highlights of this column: http://www.bianceng.cn/webkf/PHP/

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.