Phpmailer using 163 mail to send an email example

Source: Internet
Author: User
Tags word wrap

Note: If your server has installed a coffee selling and account opening virus maximum protection function we need to close a mail protection Oh, otherwise your mail will not be sent out to be this antivirus to intercept oh.

1. Scripts sent with Gmail

Code to copy code as follows
Include ("class.phpmailer.php");
Include ("class.smtp.php");
Get the contents of an external file
$mail = new Phpmailer ();
$body = file_get_contents (' contents.html ');
$body = Eregi_replace ("[]", "', $body);
Setting SMTP parameters
$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 = "[email protected]";
$mail->password = "Password";
Set the sender, preferably do not forge the address
$mail->from = "[email protected]";
$mail->fromname = "Webmaster";
$mail->subject = "This is the Subject";
$mail->altbody = $body;
$mail->wordwrap = 50; Set word Wrap
$mail->msghtml ($body);
Set Reply Address
$mail->addreplyto ("[Email protected]", "Webmaster" (www.111cn.net));
Add attachment, where the attachment is in the same directory as the script
Otherwise fill out the full path
$mail->addattachment ("attachment.jpg");
$mail->addattachment ("Attachment.zip");
Set the Mail recipient's mailbox and name
$mail->addaddress ("[Email protected]", "FirstName LastName");
Send mail using HTML format
$mail->ishtml (TRUE);
Send a message via the Send method
According to the results of the delivery of the corresponding 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

Code to copy code as follows
Setting SMTP parameters
Note that the SSL protocol is not required here
$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.

Experience sharing

Some friends refer to this tutorial to use Sina Mail login to send mail when you find that Sina Mail does not support this feature, in fact, this is not Sina mailbox does not support this feature we need to find in Sina mailbox POP3 This agreement can, account method is login Sina, We have a setting button on the right side, we can see that there is an "account setting" after the entry to the bottom of the POP3 class, we may open it, so you try again the above code can be solved Oh, have Friends department why 163 Mail not set it up, Because 163 mail by default is open POP3 Oh.
From:http://www.111cn.net/phper/php-cy/61846.htm

Phpmailer using 163 mail to send an email example

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.