perpetual
02-27-2002, 06:48 PM
Hey does anyone know where I can get a small sample / example of how to connect to a mail server using PHP? I know that you use the imap functions but does that mean you have to have imap installed? I haven't found many hosts that actually provide imap - anyone know why?
I know this is perhaps not the right forum to post this but I've found that there's quite a few knowledeable people who hang out here.
Thanks.
acidHL
02-27-2002, 06:57 PM
Im very new to PHP so bare with me ;)
IMAP is an alternative to POP, and I take it your trying to RECIVE mail via the script?
Im not quite sure but SENDING is relatively easy:
mail("$to", "$subject", "$message", "$from");
And just define the variables - they are pretty self explanatory...
:confused: :(
Examples from the PHP documentation:
mail("joecool@example.com", "My Subject", "Line 1\nLine 2\nLine 3");
mail("nobody@example.com", "the subject", $message,
"From: webmaster@$SERVER_NAME\r\n"
."Reply-To: webmaster@$SERVER_NAME\r\n"
."X-Mailer: PHP/" . phpversion());
mail("nobody@example.com", "the subject", $message,
"From: webmaster@$SERVER_NAME", "-fwebmaster@$SERVER_NAME");
/* recipients */
$to = "Mary <mary@example.com>" . ", " ; //note the comma
$to .= "Kelly <kelly@example.com>";
/* subject */
$subject = "Birthday Reminders for August";
/* message */
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
/* To send HTML mail, you can set the Content-type header. */
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
/* additional headers */
$headers .= "From: Birthday Reminder <birthday@example.com>\r\n";
$headers .= "Cc: birthdayarchive@example.com\r\n";
$headers .= "Bcc: birthdaycheck@example.com\r\n";
/* and now mail it */
mail($to, $subject, $message, $headers);
allera
02-27-2002, 08:24 PM
I don't think he's trying to send mail from the server. I think he's trying to connect to a mail server via IMAP.
Excellent place to start:
http://www.php.net/manual/en/ref.imap.php
perpetual
02-27-2002, 08:47 PM
I don't think he's trying to send mail from the server. I think he's trying to connect to a mail server via IMAP.
yeah. that's right. Now that I read the php.net link again, I just didn't realised that I needed the /pop3 for pop3 connections :stickout
$mbox = imap_open ("{localhost:110/pop3}INBOX", "user_id", "password");
I want to be able to READ email from POP3 though. Anyone got any examples?
Ahmad
02-28-2002, 12:23 PM
haven't done that before, but if there isn't any ready made module to do that, you can always use sockets to communicate to the POP server. You'll need to read about the POP3 protocol, but its fairly easy.
ASPCode.net
02-28-2002, 02:26 PM
http://www.thewebmasters.net/php/POP3.phtml
a POP3 class
.::DefCon::.
02-28-2002, 04:39 PM
Do a search at www.hotscripts.com :)