Php verifies smtp information correctly. recently, dede is used as the site. you can see the setting for enabling smtp to send emails in the background, but it is not verified. How can I check whether the smtp information is correct, including the port, user name, and password? Ask for php code implementation and output these error messages, which will be presented in 100! Thank you.
Reply to discussion (solution)
Dede enables smtp mail sending settings. are you installing a plug-in?
The latest dede installed locally does not seem to have this function set.
Back to Daniel upstairs, I only need to verify that smtp information is correct and do not need to make a dede plug-in.
// Open the smtp server port
$ Fp = @ fsockopen ($ smtp_host, 25 );
If (! $ Fp)
Echo"Error:Cannot conect to ". $ smtp_host ."
";
$ Smtp = array (// 1, EHLO, expect to return 220 or 250 array ("EHLO ". $ loc_host. $ lb, "220,250", "HELO error:"), // 2. send Auth Login, expect to return 334 array ("auth login ". $ lb, "334", "AUTH error:"), // 3. the user name sent with Base64 encoding is expected to return the 334 array (base64_encode ($ smtp_acc ). $ lb, "334", "AUTHENTIFICATION error:"), // 4. send the Base64-encoded password and expect to return the 235 array (base64_encode ($ smtp_pass ). $ lb, "235", "AUTHENTIFICATION error:"); // 5. send Mail From, expect to return 250 $ smtp [] = array ("MAIL FR OM: <". $ from."> ". $ lb," 250 "," mail from error: "); // 6. send Rcpt. Expect TO return 250 $ smtp [] = array ("rcpt to: <". $. "> ". $ lb, "250", "rcpt to error:"); // 7. send DATA, expect TO return 354 $ smtp [] = array ("DATA ". $ lb, "354", "DATA error:"); // 8.0, send From $ smtp [] = array ("From :". $ from. $ lb, "", ""); // 8.2, send To $ smtp [] = array (":". $. $ lb, "", ""); // 8.1, sending Title $ smtp [] = array ("Subject :". $ subject. $ lb, "", ""); $ result_str = ""; // send commands/data foreach ($ smtp as $ req) in the smtp array) {// send message @ fputs ($ fp, $ req [0]); // if you want to receive information returned by the server, if ($ Req [1]) {// receive information while ($ result = @ fgets ($ fp, 1024) {if (substr ($ result) = "") {break ;}}; if (! Strstr ($ req [1], substr ($ result, 0, 3) {$ result_str. = $ req [2]. $ result ."
";}}// Close the connection @ fclose ($ fp); return $ result_str ;}
I have never tried to verify the smtp port, user name, and password. The port is okay. However, if the user name and password are used, I can only try to request to determine the port...
Function smtp_sockopen_relay ()
{
$ This-> log_write ("Trying to". $ this-> relay_host. ":". $ this-> smtp_port. "\ n ");
$ This-> sock = @ fsockopen ($ this-> relay_host, $ this-> smtp_port, $ errno, $ errstr, $ this-> time_out );
If (! ($ This-> sock & $ this-> smtp_ OK ()))
{
$ This-> log_write ("Error: Cannot connenct to relay host". $ this-> relay_host. "\ n ");
$ This-> log_write ("Error:". $ errstr. "(". $ errno. ") \ n ");
Return FALSE;
}
$ This-> log_write ("Connected to relay host". $ this-> relay_host. "\ n ");
Return TRUE ;;
}