[PHP] mail() doet niks

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

  • TheLunatic
  • Registratie: April 2001
  • Laatst online: 16-08 21:48

TheLunatic

Ouwe boxen.

Topicstarter
Om te beginnen: ik zou dit topic niet durven plaatsen als ik niet eerst heel goed zou hebben gezocht. Ik loop al langer rond met dit probleem, dacht dat het misschien aan de mailserver zou liggen, maar nu heb ik de functie echt nodig en het werkt nog steeds niet.

Mijn mailserver is van XS4ALL, smtp.xs4all.nl is het adres van de server. Mailen via Outlook gaat, dus de server is up. Ik internet ook via XS4ALL.

Dit is mijn PHP-code (erg basic dus):
PHP:
1
2
3
4
5
6
  $to="julesvdz@xs4all.nl";
  $subject="test";
  $body="werkt !";
  $from="kerkdriel@xs4all.nl";
  
  mail($to, $subject, $body, "From: " . $from) or die("Can't send mail.");


En dit is mijn php.ini in c:\windows\
code:
1
2
3
4
5
6
7
8
9
[mail function]
; For Win32 only.
SMTP = smtp.xs4all.nl

; For Win32 only.
sendmail_from = kerkdriel@xs4all.nl

; For Unix only.  You may supply arguments as well (default: 'sendmail -t -i').
;sendmail_path =


Naar mijn mening allemaal correct. Ook wat ik vind met de search en op http://nl.php.net/manual/en/function.mail.php wijst me op deze instellingen.

Toch is de output als volgt:
Warning: Failed to Connect in c:\apache\htdocs\mailtest\index.php on line 9
Can't send mail.
Voor de duidelijkheid: 'Can't send mail' wordt geschreven door mijn code (die());
Ook als ik het 4e argument ("From: " . $from) weglaat werkt het niet en krijg ik exact dezelfde melding.

Heeft iemand enig idee wat er fout gaat ?

Mother, will they like this song?


Acties:
  • 0 Henk 'm!

  • Neus
  • Registratie: Maart 2001
  • Laatst online: 18-09 10:45

Neus

www.zenaconsult.com

Bij XS4All moet je ook voor je SMTP server je usernaam en password gebruiken, anders kom je er niet bij.


Quote van de manual site met comments:
If you want to send emails through socket instead sendmail, you could use this function ( maybe improved, but works well specially on Win98 / Apache / Php4.3.4 ). It sends nice HTML mails :)) and support both methods $auth=0, try no authentification, and $auth=1 with user / pass. I figured out an example to use :

Enjoy :))
This simple function is a simplified version of mail class, found on net, phpprojekt
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
75
76
<? php

   
//mail($catre, $subject, $message, $headers); //old fashion mail, using sendmail, useful on linux
sock_mail(1,$catre,$subject,$message,$headers,$from);//sock version, usable on Win32

//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 = "your_mail_account";        //account
       $smtp_pass="your_mail_password";            //password
       $smtp_host="your_mail_server";    //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;
   }  

?>

[ Voor 95% gewijzigd door Neus op 01-05-2004 16:17 ]

Very funny, Scotty... Now beam down my clothes !


Acties:
  • 0 Henk 'm!

  • TheLunatic
  • Registratie: April 2001
  • Laatst online: 16-08 21:48

TheLunatic

Ouwe boxen.

Topicstarter
Cool, dat werkt idd wel ! De mail komt aan, maar ik krijg op m'n scherm nog wel deze error:
AUTH error:.503 5.3.3 AUTH not available
AUTHENTIFICATION error : .500 5.5.1 Command unrecognized: "whatever="
AUTHENTIFICATION error : .500 5.5.1 Command unrecognized: "whatever=="
Weet je daar toevallig ook een oplossing voor ?

[ Voor 10% gewijzigd door TheLunatic op 01-05-2004 16:38 ]

Mother, will they like this song?


Acties:
  • 0 Henk 'm!

  • stekkel
  • Registratie: Augustus 2001
  • Laatst online: 17-09 08:05
ik zou je vorige bericht snel editen omdat daar je username / password in base64 encoded vorm staat en dat is te decoderen.

en probeer wat je aan het doen bent eens zonder authentication. De smtp server zegt namelijk dat AUTH niet ondersteund is.

[ Voor 35% gewijzigd door stekkel op 01-05-2004 16:37 ]


Acties:
  • 0 Henk 'm!

  • TheLunatic
  • Registratie: April 2001
  • Laatst online: 16-08 21:48

TheLunatic

Ouwe boxen.

Topicstarter
stekkel schreef op 01 mei 2004 @ 16:35:
ik zou je vorige bericht snel editen omdat daar je username / password in base64 encoded vorm staat en dat is te decoderen.

en probeer wat je aan het doen bent eens zonder authentication. De smtp server zegt namelijk dat AUTH niet ondersteund is.
Okay thanks, ge-edit ..!

Maar als ik MiniMan goed begrijp is het bij XS4ALL juist nodig om authentication te gebruiken, omdat je anders niet op de server komt... Jij beweert nu het tegenovergestelde. Ik ga het even proberen, beetje prutsen aan die functie maar ik vind 't vreemd dat jullie het tegenovergestelde (lijken te) beweren.

Mother, will they like this song?


Acties:
  • 0 Henk 'm!

  • stekkel
  • Registratie: Augustus 2001
  • Laatst online: 17-09 08:05
Ik keek net ff op de xs4all site en daar staat nergens dat je authentication voor smtp moet gebruiken. Zelfs de help voor het opzetten van email accounts in de verschillende mailclients vermeldt nergens authentication voor smtp.xs4all.nl.

Acties:
  • 0 Henk 'm!

  • TheLunatic
  • Registratie: April 2001
  • Laatst online: 16-08 21:48

TheLunatic

Ouwe boxen.

Topicstarter
Ja maar waarom werkt mail() dan niet gewoon ??

Als ik de authenticatie uit bovenstaande functie rip werkt het trouwens errorloos, maar ik heb toch nog graag een antwoord op mijn vraag :)

Mother, will they like this song?


Acties:
  • 0 Henk 'm!

  • stekkel
  • Registratie: Augustus 2001
  • Laatst online: 17-09 08:05
geen idee, ik heb de mail functie nog nooit gebruikt en doe alles via sockets.

Acties:
  • 0 Henk 'm!

  • igmar
  • Registratie: April 2000
  • Laatst online: 03-09 22:58

igmar

ISO20022

MiniMan schreef op 01 mei 2004 @ 16:14:
Bij XS4All moet je ook voor je SMTP server je usernaam en password gebruiken, anders kom je er niet bij.
Alleen als je via een non-xs4all IP zit. Indien je gewoon via hun netwerk zit is een username / pass niet nodig.

Acties:
  • 0 Henk 'm!

  • MatHack
  • Registratie: Oktober 2001
  • Niet online

MatHack

Dev by day, Gamer by night

Ik gebruik hier ook gewoon de SMTP-server van XS4All (en ja dat is ook mijn ISP) zonder username & password. Wat gebeurd er als je de or die(...) weglaat?

[ Voor 22% gewijzigd door MatHack op 02-05-2004 12:02 ]

There's no place like 127.0.0.1

Pagina: 1