PHP uses Phpmailer to send mail

Source: Internet
Author: User
Tags word wrap
Phpmailer is a free PHP mail send plug-in, we can use Phpmailer login to our designated mail and then use this email to us automatically email, this now free mailbox like 163,sina support, All right, crap don't say much. To see a phpmainer 163 email it.

It's a good choice to send mail with an out-of-the-box SMTP server, which is Phpmailer (Version 5.2.0) and the SMTP server for Gmail and 163.

1. Scripts sent with Gmail

Include ("class.phpmailer.php"); Include ("class.smtp.php");//Gets the contents of an external file $mail = new Phpmailer (); $body = File_get  _contents (' contents.html '); $body = Eregi_replace ("[\]", "", $body);//Set SMTP parameter $MAIL->ISSMTP (); $mail->smtpauth    = true; $mail->smtpkeepalive = true; $mail->smtpsecure = "SSL"; $mail->host = "smtp.gmail.com"; $mail->port = 465;//fill in your Gmail account and password $mail->username = "yourname@gmail.com"; $mail->password = "Password";//Set the sender, preferably do not forge the address $ Mail->from = "yourname@gmail.com"; $mail->fromname = "Webmaster"; $mail->subject = "This is the Subject"; $mail ->altbody = $body; $mail->wordwrap = 50; Set Word wrap$mail->msghtml ($body);//sets the reply address $mail->addreplyto ("yourname@gmail.com", "Webmaster");//Add attachments, Here the attachment is in the same directory as the script//otherwise fill in the full path $mail->addattachment ("Attachment.jpg"); $mail->addattachment ("Attachment.zip");// Set the mail receiver's mailbox and name $mail->addaddress ("toname@gmail.com", "FirstName LastName");//send mail using HTML format $mail->ishtml (TRUE) ;//Send mail via Send method//according toSend the result to do the appropriate processing if (! $mail->send ()) {echo "Mailer Error:". $mail->errorinfo;} else {echo "Message has been sent";}

2. Use 163 scripts to send messages

You only need to change your SMTP configuration and account password, and the SMTP configuration is as follows

Set SMTP parameters//Note there is no need for SSL protocol $mail->issmtp (); $mail->smtpauth  = true; $mail->smtpkeepalive = true; $mail- >host    = "smtp.163.com"; $mail->port    = 25;

Test pass in local wampserver environment, need to open Php_openssl extension.

Summary : The above is the entire content of this article, I hope to be able to help you learn.

Related recommendations:

PHP operation MySQL Database and Session dialog method

PHP three common techniques for traversing trees

Definition and usage of Phpzip class

Related Article

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.