tags:

views:

147

answers:

2

Hi

Send email using mail function working fine. but my question is how to auto save the mail in sent items folder when mail sent

i m using own smtp server and port no is 25

is any config needed on php ini file or i may use imap

my code is as follows

<?php
function send_email($from, $to, $subject, $message){
 $headers = "From: ".$from."\r\n";
 $headers .= "Reply-To: ".$from."\r\n";
 $headers .= "Return-Path: ".$from."\r\n";
 $headers .= "Content-type: text/html\r\n"; 

 if (mail($to,$subject,$message,$headers) ) {
    echo "email sent";
 } else {
    echo "email couldn't be sent";
 }
}

$subject = "Helloooo!";
$message .= "<html><body>";
$message .= "<b>Hey! How are you today?</b>";
$message .= "<br>Regards";
$message .= "</body></html>";
send_email("frm addr", "[email protected]", 
 $subject , 
 $message);
?>

"frm addr" is my own web address which is provided by my mail server

how to store or automatically save the mails to my sent item folder whenever i send a mail using the above function

with thanks in adv

R.Saravanakumar

+7  A: 

You have to understand the mail() function works on a remote server. The function you send the E-Mail with does not know the concept of a "Sent mail" folder.

That said, it would probably be possible to have the mail server place a copy of the message in the "sent" folder of an IMAP mailbox running on the same server. That includes a lot of hassle, though, and requires root access to the server.

A much easier solution is having the mail() function send you a copy of every sent mail, and to set up an Outlook rule to copy those mails into your "sent" folder.

For that, you could for example add a specific string (like "mail sent from form 1234567", some random number that is unlikely to be repeated in a normal mail) to the subject when sending your copy. Your Outlook rule would then look out for mails containing that subject, and move them into the "Sent" folder (or any other folder, for that matter).

Pekka
+1  A: 

Storing a sent mail in a "sent item"-folder is done by the client which sends out emails, not the mailserver (which is used by mail()).

The PHP-mail()-function will "just" send out email, communicating with the server, without storing it anywhere, so to have your send messages stored anywhere you'll have to create your own "mail-client" which handles mails and folders. I doubt that's worth the effort, so why not just send your mails to a second mail-account and store them there?

Select0r