Send mail with Phpmailer in PHP

Source: Internet
Author: User
Tags format echo message include mail require domain name

In PHP, you provide a mail-sending function mail function that sends e-mail directly in your program, but it requires the server to support SendMail
Or you must set up a mail-sending server that does not require relaying, but it is almost impossible to find a message-sending relay that does not require authentication.
So using mail functions often fails to send email successfully.

If you are familiar with the SMTP protocol, combined with the socket function can write efficient and stable mail delivery program, but for the general user is too difficult. Fortunately, the Internet has been a lot of other people write good mail delivery module, we only need to download simple call can be very convenient.

Here we recommend to users a very powerful PHP, Easy-to-use and free of the SMTP class module-phpmailer,

Phpmailer is a PHP function package that is used to send e-mail. The features it provides include:
*. Specify multiple recipients, CC addresses, dark addresses, and reply-to addresses when sending mail
*. Support for multiple message codes including: 8bit,base64,binary and Quoted-printable
*. Support SMTP Authentication
*. Support for redundant SMTP servers
*. Support for messages with attachments and HTML-formatted messages
*. Custom message headers
*. Support for embedding pictures in messages
*. Flexible Commissioning
*. tested and compatible SMTP servers include: Sendmail,qmail,postfix,imail,exchange, etc.
*. can be run on any platform

After downloading the component, write the code as follows to enable PHP to send messages online.


One: HTML programs


<body>
Please enter the <font color= "#FF6666" > Mail </font> Email address:
<form name= "Phpmailer" action= "send.php" method= "POST" >
<input type= "hidden" name= "submitted" value= "1"/>
e-mail address: <input type= "text" size= "a" name= "addresses"/>
<br/>
<input type= "Submit" value= "Send"/>
</form>
</body>


Second: PHP program

<?php
Require ("class.phpmailer.php");//The downloaded file must be placed in the directory where the file is located
$mail = new Phpmailer ()//create Mail Send Class
$address = $_post[' address '];
$mail->issmtp ();//Send Using SMTP
$mail->host = "mail.xxxxx.com"; Your Business Post office domain name
$mail->smtpauth = true; To enable the SMTP authentication feature
$mail->username = "user@xxxx.com"; Post Office username (please fill in the full email address)
$mail->password = "Hu Jintao"; Post Office password
$mail->from = "user@xxxx.com"; Mail Sender email Address
$mail->fromname = "Your name";
$mail->addaddress ("$address", "");//recipient address, can be replaced by any e-mail message that you want to receive mail, in the form of addaddress ("addressee Email", "Recipient Name")
$mail->addreplyto ("", "");
$mail->addattachment ("/var/tmp/file.tar.gz");//Add Attachments
$mail->ishtml (TRUE);//Set email format to HTML//whether to use HTML format
$mail->subject = "phpmailer test mail"; Message headers
$mail->body = "Hello, this is Test mail"; Message content
$mail->altbody = "This are the body in plain text for non-html mail clients"; Additional information that can be omitted
if (! $mail->send ())
{
Echo message failed to send. <p> ";
echo "Error Reason:". $mail->errorinfo;
Exit
}
echo "Mail sent successfully";
?>



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.