Ik probeer een externe mailserver te gebruiken voor het verzenden van mail. Nu zijn daar al vele topics over, maar die gaan vaak over de instellingen van PHP zelf. Dit terwijl ik in dit geval geen root access heb en het dus moet doen met gewone PHP-code.
Nu heb ik een topic de volgende PHP-code gevonden:
Of ik dit nu oproep met
of
ik krijg telkens de volgende foutmelding:
Dan is de foutmelding korter (niet beter helaas....):
Overigens wordt in dit topic gemeld dat direct afleveren bij de SMTP-server kan, als de ontvanger in hetzelfde domain zit. Dat is het geval, dus mocht dit een andere oplossing ook mogelijk maken....
Nu heb ik een topic de volgende PHP-code gevonden:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
| <?php //this is the sock mail function function sock_mail($auth,$to, $subj, $body, $head, $from) { $lb="\r\n"; //linebreak $body_lb="\r\n"; //body linebreak $loc_host = "localhost"; //localhost $smtp_acc = "************"; //account $smtp_pass="************"; //password $smtp_host="smtp.uci.kun.nl"; //server SMTP $hdr = explode($lb,$head); //header if($body) {$bdy = preg_replace("/^\./","..",explode($body_lb,$body));} // build the array for the SMTP dialog. Line content is array(command, success code, additonal error message) if($auth == 1){// SMTP authentication methode AUTH LOGIN, use extended HELO "EHLO" $smtp = array( // call the server and tell the name of your local host array("EHLO ".$loc_host.$lb,"220,250","HELO error: "), // request to auth array("AUTH LOGIN".$lb,"334","AUTH error:"), // username array(base64_encode($smtp_acc).$lb,"334","AUTHENTIFICATION error : "), // password array(base64_encode($smtp_pass).$lb,"235","AUTHENTIFICATION error : ")); } else {// no authentication, use standard HELO $smtp = array( // call the server and tell the name of your local host array("HELO ".$loc_host.$lb,"220,250","HELO error: ")); } // envelop $smtp[] = array("MAIL FROM: <".$from.">".$lb,"250","MAIL FROM error: "); $smtp[] = array("RCPT TO: <".$to.">".$lb,"250","RCPT TO error: "); // begin data $smtp[] = array("DATA".$lb,"354","DATA error: "); // header $smtp[] = array("Subject: ".$subj.$lb,"",""); $smtp[] = array("To:".$to.$lb,"",""); foreach($hdr as $h) {$smtp[] = array($h.$lb,"","");} // end header, begin the body $smtp[] = array($lb,"",""); if($bdy) {foreach($bdy as $b) {$smtp[] = array($b.$body_lb,"","");}} // end of message $smtp[] = array(".".$lb,"250","DATA(end)error: "); $smtp[] = array("QUIT".$lb,"221","QUIT error: "); // open socket $fp = @fsockopen($smtp_host, 25); if (!$fp) echo "<b>Error:</b> Cannot conect to ".$smtp_host."<br>"; $banner = @fgets($fp, 1024); // perform the SMTP dialog with all lines of the list foreach($smtp as $req){ $r = $req[0]; // send request @fputs($fp, $req[0]); // get available server messages and stop on errors if($req[1]){ while($result = @fgets($fp, 1024)){if(substr($result,3,1) == " ") { break; }}; if (!strstr($req[1],substr($result,0,3))) echo"$req[2].$result<br>"; } } $result = @fgets($fp, 1024); // close socket @fclose($fp); return 1; } ?> |
Of ik dit nu oproep met
code:
1
| sock_mail(0,"********@****.nl", "Testje", "Test", $head, "***@***.***.nl"); |
of
code:
1
| sock_mail(1,"********@****.nl", "Testje", "Test", $head, "***@***.***.nl"); |
ik krijg telkens de volgende foutmelding:
Een eenvoudiger scriptje gevonden via php.net/mail is het volgendeError: Cannot conect to smtp.uci.kun.nl
HELO error: .
MAIL FROM error: .
RCPT TO error: .
DATA error: .
DATA(end)error: .
QUIT error: .
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| <? include("Mail.php"); $recipients = "info*********.nl"; $headers["From"] = "***@*****.nl"; $headers["To"] = "***@*****.nl"; $headers["Subject"] = "Test message"; $body = "TEST MESSAGE!!!"; $params["host"] = "smtp.uci.kun.nl"; $params["port"] = "25"; $params["auth"] = true; $params["username"] = "*******"; $params["password"] = "*******"; // Create the mail object using the Mail::factory method $mail_object =& Mail::factory("smtp", $params); $mail_object->send($recipients, $headers, $body); ?> |
Dan is de foutmelding korter (niet beter helaas....):
Opvallend is: een telnet naar deze server werkt prima.Warning: fsockopen(): unable to connect to 131.174.93.49:25 in /usr/lib/php/Net/Socket.php on line 108
Overigens wordt in dit topic gemeld dat direct afleveren bij de SMTP-server kan, als de ontvanger in hetzelfde domain zit. Dat is het geval, dus mocht dit een andere oplossing ook mogelijk maken....