|
Sending Mail With PHP3
Tim Perdue
Server scripting languages like Lasso and Java servlets make sending mail
so complicated that you'd rather avoid it at all costs. Until recently,
I have been relying on a cheap (read "free") perl script from
cgi-resources.com, but
I want to be able to do this from PHP.
Yesterday (1999-02-20), I decided to give email a whirl with PHP3.
I needed to have a customized "thank you" page after sending the mail -
like the rest of geocrawler.com and
gotocity.com, the response page
had to be co-brandable and customizable.
No problem for PHP. I started my research by visiting the
Sample Code Archive. I wound up finding some really cool code by
Jon Stevens that can take an email address
and verify that it can actually receive the email. So if you want to get into
some really serious form validation, you can (I didn't go that far yet, but will soon).
Jon Stevens' Code
<?php
function validateEmail ($email) {
global $SERVER_NAME;
$return = array (false, "");
list ($user, $domain) = split ("@", $email, 2);
$arr = explode (".", $domain);
$count = count ($arr);
## Here starts the modification (E.Soysal)
if (($count> 2) and ($arr[$count - 2]=='com' or $arr[$count - 2]=='org' or
$arr[$count - 2]=='net' or $arr[$count - 2]=='edu' or
$arr[$count - 2]=='mil' or $arr[$count - 2]=='k12')) {
$tld = $arr[$count - 3].".".$arr[$count - 2] . "." . $arr[$count - 1];
} else {
## End of modification
$tld = $arr[$count - 2] . "." . $arr[$count - 1];
}
if (checkdnsrr ($tld, "MX")) {
if (getmxrr ($tld, $mxhosts, $weight)) {
for ($i = 0; $i < count ($mxhosts); $i++) {
$fp = fsockopen ($mxhosts[$i], 25);
if ($fp) {
$s = 0;
$c = 0;
$out = "";
set_socket_blocking ($fp, false);
do {
$out = fgets ($fp, 2500);
if (ereg ("^220", $out)) {
$s = 0;
$out = "";
$c++;
} else if (($c > 0) && ($out == "")) {
break;
} else {
$s++;
}
if ($s == 9999) {
break;
}
} while ($out == "");
set_socket_blocking ($fp, true);
fputs ($fp, "HELO $SERVER_NAME\n");
$output = fgets ($fp, 2000);
fputs ($fp, "MAIL FROM: <info@" . $tld . ">\n");
$output = fgets ($fp, 2000);
fputs ($fp, "RCPT TO: <$email>\n");
$output = fgets ($fp, 2000);
if (ereg ("^250", $output)) {
$return[0] = true;
} else {
$return[0] = false;
$return[1] = $output;
}
fputs ($fp, "QUIT\n");
fclose($fp);
if ($return[0] == true) {
break;
}
}
}
}
}
return $return;
}
?>
| Comments: | ||
| RE: Send Survey Results via Email | indah puspita | 02/14/05 04:08 |
| RE: Server Error | shabbir | 11/06/02 06:47 |
| RE: Can i connect to ... | Hippo | 10/21/02 14:23 |
| Send Survey Results via Email | Pushpinder Singh | 10/15/02 13:54 |
| send mail | teddy | 10/15/02 05:20 |
| Can i connect to ... | Andrei | 10/11/02 10:41 |
| RE: harrasment | caxi | 09/04/02 08:15 |
| subsequent mail() problem | Akhmad D. Sembiring | 08/31/02 04:25 |
| MINOR ERROR | Andrew Patel | 08/27/02 21:08 |
| Server Error Solution for w2k | Otaru-sama | 08/22/02 11:55 |
| harrasment | sean | 08/13/02 16:38 |
| harrasment | sean | 08/13/02 16:36 |
| Server Error | Rauj | 08/08/02 02:50 |
| RE: Server Error | Cari | 08/06/02 19:52 |
| RE: attachment on mail() function | Raj | 08/05/02 19:08 |
| RE: how to send array of values with mail() | Os2Al | 07/23/02 22:16 |
| how to send array of values with mail() | luke woollard | 07/16/02 05:22 |
| 'Failed to Connect' ERROR | Mirza Claudiu Sebastian | 06/05/02 07:53 |
| Attachments in php3 | Srikanth | 05/25/02 15:52 |
| RE: Server Error | Alex Elderson | 05/24/02 08:45 |
| this doesn't work ... | beer | 05/23/02 11:13 |
| mail() function warning: mail not.... | Pejus | 05/17/02 05:41 |
| Sending email to @AOL.COM addresses | Cotton | 05/09/02 12:43 |
| RE: attachment through smtp in php3 | P P Roday | 04/13/02 03:35 |
| RE: 'Failed to Connect' Error | Sabrina Markon | 04/03/02 19:55 |
| RE: attachment through smtp in php3 | faty | 04/03/02 11:09 |
| RE: How do I configure the outgoing mail server | denis kakooza | 03/19/02 11:36 |
| RE: from address in email | denis kakooza | 03/19/02 11:27 |
| Numbering multipart mail parts | denis kakooza | 03/19/02 10:50 |
| mail problem | aasim | 03/10/02 15:22 |
| from address in email | venkat | 02/21/02 00:58 |
| MySQL Connection Failed | CHARLES | 02/19/02 06:35 |
| i download horde & imp but i cant fix webmail | raja | 02/13/02 16:22 |
| Hello | Aor Chucha | 01/16/02 11:10 |
| Generating documentation for php code! | Ahmed | 01/15/02 02:20 |
| Some pointers... | John Kant | 01/08/02 14:48 |
| bab use imap_open | pham trung dung | 12/28/01 09:09 |
| is this useful? | Mr.Q | 12/19/01 03:24 |
| RE: disccusion forum code!!!! | Craig | 12/10/01 11:57 |
| Attachment's File Name | Steven Chalker | 12/08/01 08:46 |
| Email Formation | Mike Discenza | 11/29/01 15:27 |
| sending '1' e-mail w/ multiple rcpt's | Neal | 10/29/01 13:57 |
| relaying denied | bubi | 10/29/01 04:52 |
| How do I configure the outgoing mail server | Jon | 10/26/01 15:39 |
| disccusion forum code!!!! | simba | 10/18/01 10:29 |
| RE: AOL E-mails | MEMEyou | 10/18/01 08:04 |
| RE: AOL E-mails | Adam | 10/04/01 14:59 |
| wanttoknow | sdf | 09/20/01 13:25 |
| RE: attachment through smtp in php3 | homena | 08/31/01 05:14 |
| Hyperlink | Grami | 08/28/01 01:01 |
| Hyperlink | Grami | 08/28/01 01:00 |
| Sophea: Coding for receive mail from server | Sophea Heang | 08/21/01 04:53 |
| "this" | nick | 08/19/01 22:04 |
| RE: same as in php4? | yowen | 07/30/01 01:13 |
| mail() | Alcides | 07/26/01 08:59 |
| PHP Builder is great! | Kudos to you | 07/24/01 09:33 |
| test php | satter | 07/21/01 09:47 |
| Server Error | Tom Connor | 07/18/01 17:42 |
| Server Error | Tom Connor | 07/18/01 08:18 |
| Server Error | Tom Connor | 07/18/01 08:15 |
| RE: AOL E-mails | juanito | 07/16/01 02:42 |
| RE: comments | Dan Ludwig | 07/03/01 07:05 |
| Need Help about mail function | saeed ahmd tariq | 06/28/01 23:46 |
| RE: AOL E-mails | Cyrus Chvala | 06/23/01 15:58 |
| same as in php4? | mej!A | 06/22/01 13:44 |
| RE: attachment through smtp in php3 | anwar | 05/21/01 06:19 |
| how to send image by mail | sanjay | 05/21/01 05:54 |
| attching extra header to data | how could i attach extra header with body | 05/11/01 10:38 |
| RE: attachment through smtp in php3 | Josh | 04/16/01 10:11 |
| comments | arun | 04/10/01 02:20 |
| .com & .edu, etc., but what about .tv or .fm? | Dan Ludwig | 04/02/01 14:38 |
| your example | Victor | 03/30/01 16:34 |
| Unexpected character appended | Bhavesh Goradia | 03/28/01 07:22 |
| RE: AOL E-mails | Tanner | 03/28/01 03:26 |
| envelope "from" is not the same as message "f | oddfish | 03/15/01 07:46 |
| Bad Message destination | brandon | 02/25/01 04:03 |
| RE: Dummy, too | fallus | 02/17/01 03:03 |
| RE: 'Failed to Connect' Error | Yiannis Mavroukakis | 02/12/01 04:46 |
| attachment through smtp in php3 | sachin shah | 02/07/01 01:53 |
| Dummy, too | Olli | 02/02/01 11:24 |
| RE: dummy | bmpc | 01/11/01 17:57 |
| dummy | Emiel | 01/08/01 05:31 |
| RE: AOL E-mails | Mario Garcio | 12/14/00 13:47 |
| RE: Warning: Failed to Receive... | Mika Ylinen | 12/10/00 15:27 |
| Warning: Failed to Receive... | John | 10/11/00 18:58 |
| Where is this in "shared"? (AOL???) | Peter Huestis | 08/28/00 12:17 |
| AOL E-mails | Spencer D. Mindlin | 08/03/00 18:01 |
| RE: 'Failed to Connect' Error | Cédric CHERCHI | 08/01/00 11:48 |
| 'Failed to Connect' Error | Errol Siegel | 06/28/00 10:45 |
|
If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly. | ||


