php Send mail with phpmailer, phpmailer send mail _php tutorial

Source: Internet
Author: User
Tags php send mail word wrap

PHP sends mail with Phpmailer, Phpmailer sends mail

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 = ""; $mail->port = 465;//fill in your Gmail account and password $mail->username = ""; $mail->password = "Password";//Set the sender, preferably do not forge the address $ Mail->from = ""; $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 ("", "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 ("");// Set the mail receiver's mailbox and name $mail->addaddress ("", "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    = ""; $mail->port    = 25;

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

The above mentioned is the whole content of this article, I hope you can like. true techarticle PHP with Phpmailer to send mail, phpmailer send mail local no mail server, the use of ready-made SMTP server to send mail is a good choice, the tool used here is ...

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