Phpmailer sending mail with SMTP

Source: Internet
Author: User

<?php

Error_reporting (E_all);

Error_reporting (e_strict);

Date_default_timezone_set (' America/toronto ');

Date_default_timezone_set (Date_default_timezone_get ());

Include_once ('.. /class.phpmailer.php ');

Include ("class.smtp.php"); Optional, gets called from within class.phpmailer.php if not already loaded


$mail =new Phpmailer ();

$body = $mail->getfile (' contents.html ');

$body =eregi_replace ("[\]" ",", $body);


$mail->issmtp (); Telling the class to use SMTP

$mail->host = "smtp.126.com"; SMTP Server

$mail->port = 25; Set the SMTP port for the GMAIL server

$mail->smtpauth = true; Turn on SMTP authentication

$mail->username = "[email protected]"; SMTP username Note: Normal mail authentication does not need to add @ domain name

$mail->password = "Password"; SMTP Password

$mail->from = "[email protected]";

$mail->fromname = "name";

$mail->charset = "GB2312"; Specify the character set here!

$mail->encoding = "base64";

$mail->addaddress ("[Email protected]", "name"); Recipient's mailbox and name

$mail->addreplyto ("[Email protected]", "cgsir.com");

$mail->subject = "Phpmailer Test Subject via SMTP";

$mail->msghtml ($body);

$mail->addattachment ("Images/phpmailer.gif"); Attachment


if (! $mail->send ()) {

echo "Mailer Error:". $mail->errorinfo;

} else {

echo "Message sent!";

}


?>


Phpmailer sending mail with SMTP

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.