Php imap send message

IMAP, POP3 and NNTP

function pop3_login ( $host , $port , $user , $pass , $folder = «INBOX» , $ssl = false )
<
$ssl =( $ssl == false )? «/novalidate-cert» : «» ;
return ( imap_open ( » $folder » , $user , $pass ));
>
function pop3_stat ( $connection )
<
$check = imap_mailboxmsginfo ( $connection );
return ((array) $check );
>
function pop3_list ( $connection , $message = «» )
<
if ( $message )
<
$range = $message ;
> else <
$MC = imap_check ( $connection );
$range = «1:» . $MC -> Nmsgs ;
>
$response = imap_fetch_overview ( $connection , $range );
foreach ( $response as $msg ) $result [ $msg -> msgno ]=(array) $msg ;
return $result ;
>
function pop3_retr ( $connection , $message )
<
return( imap_fetchheader ( $connection , $message , FT_PREFETCHTEXT ));
>
function pop3_dele ( $connection , $message )
<
return( imap_delete ( $connection , $message ));
>
function mail_parse_headers ( $headers )
<
$headers = preg_replace ( ‘/\r\n\s+/m’ , » , $headers );
preg_match_all ( ‘/([^: ]+): (.+?(?:\r\n\s(. +?))*)?\r\n/m’ , $headers , $matches );
foreach ( $matches [ 1 ] as $key => $value ) $result [ $value ]= $matches [ 2 ][ $key ];
return( $result );
>
function mail_mime_to_array ( $imap , $mid , $parse_headers = false )
<
$mail = imap_fetchstructure ( $imap , $mid );
$mail = mail_get_parts ( $imap , $mid , $mail , 0 );
if ( $parse_headers ) $mail [ 0 ][ «parsed» ]= mail_parse_headers ( $mail [ 0 ][ «data» ]);
return( $mail );
>
function mail_get_parts ( $imap , $mid , $part , $prefix )
<
$attachments =array();
$attachments [ $prefix ]= mail_decode_part ( $imap , $mid , $part , $prefix );
if (isset( $part -> parts )) // multipart
<
$prefix = ( $prefix == «0» )? «» : » $prefix .» ;
foreach ( $part -> parts as $number => $subpart )
$attachments = array_merge ( $attachments , mail_get_parts ( $imap , $mid , $subpart , $prefix .( $number + 1 )));
>
return $attachments ;
>
function mail_decode_part ( $connection , $message_number , $part , $prefix )
<
$attachment = array();

if( $part -> ifdparameters ) <
foreach( $part -> dparameters as $object ) <
$attachment [ strtolower ( $object -> attribute )]= $object -> value ;
if( strtolower ( $object -> attribute ) == ‘filename’ ) <
$attachment [ ‘is_attachment’ ] = true ;
$attachment [ ‘filename’ ] = $object -> value ;
>
>
>

Читайте также:  Internal method calls java

if( $part -> ifparameters ) <
foreach( $part -> parameters as $object ) <
$attachment [ strtolower ( $object -> attribute )]= $object -> value ;
if( strtolower ( $object -> attribute ) == ‘name’ ) <
$attachment [ ‘is_attachment’ ] = true ;
$attachment [ ‘name’ ] = $object -> value ;
>
>
>

$attachment [ ‘data’ ] = imap_fetchbody ( $connection , $message_number , $prefix );
if( $part -> encoding == 3 ) < // 3 = BASE64
$attachment [ ‘data’ ] = base64_decode ( $attachment [ ‘data’ ]);
>
elseif( $part -> encoding == 4 ) < // 4 = QUOTED-PRINTABLE
$attachment [ ‘data’ ] = quoted_printable_decode ( $attachment [ ‘data’ ]);
>
return( $attachment );
>
?>

[EDIT BY danbrown AT php DOT net: Contains a bugfix by «mn26826» on 09-JUN-2010, which fixed the erroneous reference to $imap as the parameter passed to imap_mailboxmsginfo() within the user function pop3_stat(). This was intended to be $connection.] [EDIT BY visualmind AT php DOT net: Contains a bugfix by «elias-jobview» on 17-AUG-2010, which fixed the error in pop3_list function which didn’t have: return $result] [EDIT BY danbrown AT php DOT net: Contains a bugfix by «chrismeistre» on 09-SEP-2010, which fixed the erroneous reference to $mbox (should be $connection) in the pop3_list() function.]

Источник

imap_mail

This function allows sending of emails with correct handling of Cc and Bcc receivers.

The parameters to , cc and bcc are all strings and are all parsed as » RFC822 address lists.

Parameters

As string with additional headers to be set on the mail

The receivers specified in bcc will get the mail, but are excluded from the headers.

Use this parameter to specify return path upon mail delivery failure. This is useful when using PHP as a mail client for multiple users.

Return Values

Returns true on success or false on failure.

Changelog

See Also

User Contributed Notes 4 notes

In response to Mathias Rav’s comment.

While imap_mail might have this $rpath bug, it is hardly comparable to mail, because mail only uses the default send mail server account, and not a real mailbox, which you can programmatically interrogate and clean up.

Читайте также:  Image position top left css

Using the imap extension allows proper mail management and operation, like users not getting the cryptic server account name followed by ‘on behalf of’ the ‘From’ address that mail sourced emails show on some recipient clients.

As per http://bugs.php.net/bug.php?id=30688 the $rpath argument is ignored, and since the (as of now) 4 year old bug is tagged WONTFIX in the bug tracker, this function is effectively deprecated in favour of mail().

Extending the above note.
When the socket connection is stablished, it works exactly as if you had openned a telnet connection to the news server. If you don’t know what kind of headers you have to send to the news server, then I’ll suggest that you better give it a try and play with a telnet connection like this:

telenet news.servername.com 119

telnet news.euroconnect.dk 119
Trying 195.184.44.30.
Connected to news.euroconnect.net (195.184.44.30).
Escape character is ‘^]’.
200 news.euroconnect.net (Typhoon v1.2.1)

then you’ll receive confirmation from the server that you are connected. Now type «help» and enter, and you’ll see what commands are supported.

help
100 Legal Commands
article [|number]
authinfo type value
body [|number]
date
group newsgroup
head [|number]
help
last
list [active wildmat|active.times|counts wildmat]
list [overview.fmt|newsgroups wildmat]
listgroup newsgroup
mode reader
newgroups yyyymmdd hhmmss [GMT]
newnews newsgroups yyyymmdd hhmmss [GMT]
next
post
stat [|number]
xhdr field [range]
xover [range]
xpat field range pattern
quit

If you want to post a message, you can start by entring the «post» command.

post
340 Send Article to be Posted

From here you can start to enter the header information.
The most important headers are:
From:
Subject:
Newsgroup:

Читайте также:  Using script in html

after the «:» a «white space» must follow.

If you are posting the multipart message then remember
MIME-Version: 1.0

This one is also one of the important headers when you are posting a multipart message. The boundary must follow the content type in the same line.

Content-Type: multipart/mixed; boundary=»————4A11A9ABCFCA70DD4E0C3605″

Take a look at the article below to find out more about headers and packing of the message.

Источник

PHP — imap_mail() Function

PHP−IMAP functions helps you to access email accounts, IMAP stands for Internet Mail Access Protocol using these functions you can also work with NNTP, POP3 protocols and local mailbox access methods.

The imap_mail() function accepts three string values representing to address, subject, and message body as parameters and sends the given message.

Syntax

imap_mail ($to, $subject, $message [,$additional_headers, $cc, $bcc, $rpat]);

Parameters

This is a string value representing the senders address.

This is a string value representing the subject of the mail.

This is a string value representing the mail body.

additional_headers (Optional)

This is a string value representing the additional headers.

This is a string value representing the cc address.

This is a string value representing the bcc address.

This is a string value representing the return path upon the delivery failure.

Return Values

This function returns a Boolean value which is TRUE in case of success and FALSE in case of a failure.

PHP Version

This function was first introduced in PHP Version 4 and works in all the later versions.

Example

Following example demonstrates the usage of the imap_mail() function −

Output

This will generate the following output −

Example

Following is an example of the above function with the optional parameters −

Output

This will generate the following output −

Источник

Оцените статью