Some of the most commonly used mail-sending code in PHP

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags code content echo email example function imap_open link

The following email code, using an IMAP and PHP tutorial with the mail function to the example, very method, there is a third party plug-ins Oh, phpmailer to send mail.

<?php
Connect an IMAP server link with an IMAP port of 143.
$mbox = Imap_open ("{Localhost:143}inbox", "user_id", "password");
Connection POP3 Server link, POP3 port is 110.
$mbox = Imap_open ("{Localhost/pop3:110}inbox", "user_id", "password");
Connect to the NNTP Server link, NNTP has a port of 119.
$NNTP = Imap_open ("{localhost/nntp:119}comp.test", "" "" ");
?>

<?php
Connecting to an IMAP server
$mbox = Imap_open ("{imap.example.org}", "username", "password", Op_halfopen)
Or Die (Connection failed:. Imap_last_error ());
$list = Imap_getmailboxes ($mbox, "{imap.example.org}", "*");
if (Is_array ($list)) {
foreach ($list as $key => $val) {
echo "($key)";
Echo Imap_utf7_decode ($val->name). ",";
echo "". $val->delimiter. "',";
Echo $val->attributes. "<br/>n";
}
else {
echo "Imap_getmailboxes failed:". Imap_last_error (). "N";
}
Turn off IMAP connections
Imap_close ($mbox);
?>

<?php
Mail ("163@163.com", "Welcome", "Hello, hi!");
?>

<?php
//define boundary line
$boundary = Uniqid ("");
//Generate headers
$header = "From: $fromnContent-type:multipart/mixed
boundary= "$boundary" Nx-mailer:phpnx-priority:3 ";
//Get MIME type of attachment file
$mimetype = Mime_content_type (' test.zip ')
//Get Name of attachment file
$attach = ' test.zip '
// Encode and segment attachment files
$fp = fopen ($attach, "R");
$content = Fread ($fp, FileSize ($attach));
$content = Chunk_split ( Base64_encode ($content));
//Generate message body
$body = "
--$boundary
Content-type:text/plain charset=iso-8859-1
Content-transfer-encoding:8bit
$message
--$boundary
Content-type: $mimeType; name= $filename
Content-disposition:attachment; Filename= $filename
Content-transfer-encoding:base64
$content
--$boundary--";
//Send mail
Mail ($to, $ Subject, $body, $header);

<?php
$mbox =imap_open ("{Localhost:143}inbox", "myID", "MYPW");
$message =imap_body ($mbox, 1);
Imap_ Close ($mbox);
Echo$message;

 

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.