Hello,

I am trying to set email from my web server which we hosted ourself.

I already set my php.ini to smtp.indonusa.net.id and from email: davy@indonusa.net.id

to: davy_yg@yahoo.com

The program seems to works fine.

Yet, I do not receive any email yet as I suppose to. Someone mentions to me that I suppose to be able to send email from my Windows Server 2012 command prompt. I already try to send email from Windows Server 2012: email

I cannot find the telnet also. I already try to follow the instruction in the link:

C:\Users\Administrator>Telnet
'Telnet' is not recognized as an internal or external command,
operable program or batch file.

I wonder why?

Recommended Answers

All 43 Replies

For the usage of 'telnet' on Windows, you need to install the 'Telnet Client' on your system. To install the 'Telnet Client' follow the instructions:

  1. Start Server Manager. Click Start, right-click Computer, and then click Manage.
  2. If the User Account Control dialog box appears, confirm that the action it displays is what you want, and then click Continue.
  3. In the Features Summary section, click Add features.
  4. In the Add Features Wizard, select Telnet Client, and then click Next.
  5. On the Confirm Installation Options page, click Install.
  6. When installation finishes, on the Installation Results page, click Close.

Note: After the installation make sure to restart the system because sometimes the new environment variables are configured only after the restart of system.

Moreover you can also try extenal lib like 'PHPMailer' or 'Swift Mailer' to send an email in PHP.

Thanks!

I already telnet port 25 and it's closed.

How to open port 25? (for mail) in Windows Server 2012

I already try place exception for port 25 in the firewall:

http://www.wikihow.com/Open-Port-25

Microsoft Telnet> open localhost 25
Connecting To localhost...Could not open connection to the host, on port 25: Con
nect failed
Microsoft Telnet> open port 25
Connecting To port...Could not open connection to the host, on port 25: Connect
failed
Microsoft Telnet>

And it still does not work yet.

Which server you installed to send emails?

We send emails from our own server. My friend give me an empty server with Windows 2012 OS but I have to konfigure the rest myself and I am using xampp for the webserver.

I already konfigure the SMTP setting:

Setting webserver php.ini
SMTP: smtp2.indonusa.net.id
smtp_port = 25

Setting webserver sendmail/sendmail.ini
SMTP: smtp2.indonusa.net.id
smtp_port = 25

Microsoft Telnet> Microsoft Telnet> open localhost 25
Connecting To localhost...Could not open connection to the host, on port 25: Connect failed

I still wonder why?

Are you sure smtp2 exists? And which mail server is configured under this domain? Xampp doesn't provide a mail server. Also check the DNS records or your domain, I see:

> dig indonusa.net.id ANY

; <<>> DiG 9.8.1-P1 <<>> indonusa.net.id ANY
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10614
;; flags: qr rd ra; QUERY: 1, ANSWER: 8, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;indonusa.net.id.       IN  ANY

;; ANSWER SECTION:
indonusa.net.id.    21595   IN  MX  20 mx2.idcloud.biz.
indonusa.net.id.    21595   IN  MX  30 mx3.idcloud.biz.
indonusa.net.id.    21595   IN  MX  10 mx1.idcloud.biz.
indonusa.net.id.    3595    IN  NS  ns1.indonusa.net.id.
indonusa.net.id.    3595    IN  NS  ns2.indonusa.net.id.
indonusa.net.id.    21595   IN  TXT "v=spf1 a mx ptr=all"
indonusa.net.id.    3595    IN  A   202.93.143.59
indonusa.net.id.    3595    IN  SOA ns2.indonusa.net.id. admin.indonusa.net.id. 2014070603 7200 540 604800 86400

;; Query time: 61 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Fri Aug 15 12:03:50 2014
;; MSG SIZE  rcvd: 230

so it seems that your mail servers are mx[1,2,3].idcloud.biz, try to connect to number 3:

telnet mx3.idcloud.biz:25

If it works, then try to configure PHP to connect directly with this server.

Hi, I have encountered the same problem except that you are using yahoo and I am using gmail. My code and everthing else is working fine yet I am not recieving any messages. Then I found out that the problem is the email itself. So what I did is to enable the settings for less secure account (https://www.google.com/settings/security/lesssecureapps)..Then my problem was solved.

Well someone mention that mx3.idcloud.biz:25 is not our server. It's someone else.

I suppose to use telnet smtp.indonusa.net.id 25

220 EHUB3.idcloud.biz Microsoft ESMTP MAIL Service ready at Mon, 18 Aug 2014 15:
35:40 +0700

Looks like it's ready.

Here is my code:

sendmail.ini

smtp.indonusa.net.id
smtp_port=25

php.ini

SMTP = smtp.indonusa.net.id
smtp_port = 25

After the person press the next button from registration1.php he will be taken to registration2.php

registration2.php

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Registration</title>
    <meta charset="utf-8">
    <meta name="description" content="Your description">
    <meta name="keywords" content="Your keywords">
    <meta name="author" content="Your name">
    <link rel="stylesheet" href="css/style.css">
    <script src="js/jquery-1.7.1.min.js"></script>
    <script src="js/script.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#login").click(function() {
                $(".login_box").slideToggle('fast');
            });
        }); 
    </script>
    <script type="text/javascript">
        function myFunction()
        {
        document.getElementById('login_box').style.display='none';
        }
    </script>
<!--[if lt IE 8]>
   <div style=' clear: both; text-align:center; position: relative;'>
     <a href="http://windows.microsoft.com/en-US/internet-explorer/products/ie/home?ocid=ie6_countdown_bannercode">
       <img src="http://storage.ie6countdown.com/assets/100/images/banners/warning_bar_0000_us.jpg" border="0" height="42" width="820" alt="You are using an outdated browser. For a faster, safer browsing experience, upgrade for free today." />
    </a>
  </div>
<![endif]-->
<!--[if lt IE 9]>
    <script src="js/html5.js"></script>
    <link rel="stylesheet" href="css/ie.css"> 
<![endif]-->
</head>
<body>

<?php include('menu.php'); ?>

<div class="bg-main" onClick="myFunctionDisplayNone()">
    <header>
        <div class="container_24">
            <div class="wrapper">                        
                <br><br>                          
            </div><br><br>         

<?php

include('includes/koneksi.php');

$result = mysql_query("SELECT * FROM class_list 
INNER JOIN student
ON class_list.student_id = student.student_id
ORDER BY class_list_id DESC") or die(mysql_error());

$data = mysql_fetch_array($result);

$fname = $data['stu_fname'];
$lname = $data['stu_lname'];
$email = $data['stu_email'];

echo $fname;
echo $lname;
echo $email;


// write program to send email to the recorded email address

    /*
    require_once('recaptchalib.php');
    $name = strip_tags(@$_POST['name']);
    $email = str_replace(" ", "", strip_tags(@$_POST['email']));
    $phone = str_replace(" ", "", strip_tags(@$_POST['phone']));
    $message = strip_tags(@$_POST['message']); */
    $name = "name";
    $email = "davy@indonusa.net.id";
    $phone = "8888888";
    $message = "message";
    /*if (@$_POST['submit']) {*/
    if ($name&&$email&&$phone&&$message) {
    if (is_numeric($phone)) {
    /*$privatekey = "6LfjvdcSAAAAAHNcKjYO5DhTNefxYZHYcfhtrvGC";
    $resp = recaptcha_check_answer($privatekey,
    $_SERVER["REMOTE_ADDR"],
    $_POST["recaptcha_challenge_field"],
    $_POST["recaptcha_response_field"]);
    if (!$resp->is_valid) {
    //What happens when the CAPTCHA was entered incorrectly
    echo "The reCAPTCHA wasn't entered correctly.";
    } else { */
    //Your code here to handle a successful verification
    ini_set("SMTP", "smtp.indonusa.net.id");
    $body = "
    Name: ".$name."
    Phone: ".$phone."
    Email: ".$email."\n\n
    ".$message;
    mail("davy@indonusa.net.id", "Message from Innovation Website", $body, "From: ".$email);
    echo "Your message has been sent, we will get back to your shortly.";
    $name = trim("");
    $email = trim("");
    $phone = trim("");
    $message = trim("");
    }
    }
    else
    echo "There should only be numbers in your phone number.";
    /*} */
    /*else
    echo "Please fill in <b>all</b> the fields!";
    } */

?>          

<h3>PLEASE COMPLETE THE FOLLOWING REGISTRATION PROGRESS!</h3><br><br>

<form id="registration-form">

<table style="width: 1000px">

<img src="images/registrationbar2.png" height="70px" width="850px"><br><br><br>

<tr>
    <img src="images/email.png" width="50px">&nbsp;&nbsp;An email has been sent to your inbox.  Please check your email to continue.<br><br><br>
</tr>


</table>       


</form>

</div>

<?php include('footer.php'); ?>

</body>
</html>

I already test the program and check my email afterward and I do not receive any email in davy@indonusa.net.id

Any idea what else I should do to set my webserver so that it can send automatic email to my email address?

Check the error log of the mail server application. If the mail is not sent or it is rejected the log should have a trace of it.

Someone else mention that I should input the username & password which belongs to: $to

syntax: mail($to, $subject, $message, $from);

but I do not know how to code it, is this correct?

$mail->Username = ‘username email’; //username email

$mail->Password = ‘password email’; //password email

mail($to, $subject, $message, $from);

Or is there any other syntax that works?

Hello,

Here is another PHP Mailer alternative:

Yet, I still have error in it.

registration2.php

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Registration</title>
    <meta charset="utf-8">
    <meta name="description" content="Your description">
    <meta name="keywords" content="Your keywords">
    <meta name="author" content="Your name">
    <link rel="stylesheet" href="css/style.css">
    <script src="js/jquery-1.7.1.min.js"></script>
    <script src="js/script.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#login").click(function() {
                $(".login_box").slideToggle('fast');
            });
        }); 
    </script>
    <script type="text/javascript">
        function myFunction()
        {
        document.getElementById('login_box').style.display='none';
        }
    </script>
<!--[if lt IE 8]>
   <div style=' clear: both; text-align:center; position: relative;'>
     <a href="http://windows.microsoft.com/en-US/internet-explorer/products/ie/home?ocid=ie6_countdown_bannercode">
       <img src="http://storage.ie6countdown.com/assets/100/images/banners/warning_bar_0000_us.jpg" border="0" height="42" width="820" alt="You are using an outdated browser. For a faster, safer browsing experience, upgrade for free today." />
    </a>
  </div>
<![endif]-->
<!--[if lt IE 9]>
    <script src="js/html5.js"></script>
    <link rel="stylesheet" href="css/ie.css"> 
<![endif]-->
</head>
<body>

<?php include('menu.php'); ?>

<div class="bg-main" onClick="myFunctionDisplayNone()">
    <header>
        <div class="container_24">
            <div class="wrapper">                        
                <br><br>                          
            </div><br><br>         

<?php

include('includes/koneksi.php');


// PHP Mailer 

require_once(‘phpmailer/class.phpmailer.php’); //memanggil library php mailernya


define(‘GUSER’, ‘username email’);  //username email

define(‘GPWD’, ‘password email’); // password email



function smtpmailer($to, $from, $from_name, $subject, $body) {

global $error;

$mail = new PHPMailer();

$mail->IsSMTP();

$mail->SMTPDebug = 2;  // untuk memunculkan pesan error /debug di layar

$mail->SMTPAuth = true;  // authentifikasi smtp enable atau disable

$mail->SMTPSecure = '';//‘ssl atau di kosongkas jika none’; // secure transfer membutuhkan authentifikasi dari mail server

$mail->Host =’ssl://smtp.indonusa.net.id’; // masukkan nama host email “diawal ssl://”

$mail->Port = 25; //port secure ssl email

$mail->Username = ‘davy@indonusa.net.id’; //username email

$mail->Password = ‘password email’; //password email

$mail->SetFrom($from, $from_name);

$mail->Subject = $subject;

$mail->Body = $body;

$mail->AddAddress($to);

if(!$mail->Send()) {

$error = ‘Mail error: ‘.$mail->ErrorInfo;

return false;

} else {

$error = ‘Message sent!’;

return true;

}

}


// write program to send email to the recorded email address

    /*
    require_once('recaptchalib.php');
    $name = strip_tags(@$_POST['name']);
    $email = str_replace(" ", "", strip_tags(@$_POST['email']));
    $phone = str_replace(" ", "", strip_tags(@$_POST['phone']));
    $message = strip_tags(@$_POST['message']); */
    $name = "John";
    $email = "davy@indonusa.net.id";
    $phone = "8888888";
    $message = "message";
    /*if (@$_POST['submit']) {*/
    if ($name&&$email&&$phone&&$message) {
    if (is_numeric($phone)) {
    /*$privatekey = "6LfjvdcSAAAAAHNcKjYO5DhTNefxYZHYcfhtrvGC";
    $resp = recaptcha_check_answer($privatekey,
    $_SERVER["REMOTE_ADDR"],
    $_POST["recaptcha_challenge_field"],
    $_POST["recaptcha_response_field"]);
    if (!$resp->is_valid) {
    //What happens when the CAPTCHA was entered incorrectly
    echo "The reCAPTCHA wasn't entered correctly.";
    } else { */
    //Your code here to handle a successful verification
    ini_set("SMTP", "smtp.indonusa.net.id");
    $body = "
    Name: ".$name."
    Phone: ".$phone."
    Email: ".$email."\n\n
    ".$message;
    //mail("davy@indonusa.net.id", "Message from Innovation Website", $body, "From: ".$email
    smtpmailer(‘davy@indonusa.net.id’, ‘davy@indonusa.net.id’, ‘Davy’, ‘Test Email’, ‘$body’); // script kirim email

    echo "Your message has been sent, we will get back to your shortly.";
    $name = trim("");
    $email = trim("");
    $phone = trim("");
    $message = trim("");
    }
    }
    else
    echo "There should only be numbers in your phone number.";
    /*} */
    /*else
    echo "Please fill in <b>all</b> the fields!";
    } */

?>          

<h3>PLEASE COMPLETE THE FOLLOWING REGISTRATION PROGRESS!</h3><br><br>

<form id="registration-form">

<table style="width: 1000px">

<img src="images/registrationbar2.png" height="70px" width="850px"><br><br><br>

<tr>
    <img src="images/email.png" width="50px">&nbsp;&nbsp;An email has been sent to your inbox.  Please check your email to continue.<br><br><br>
</tr>


</table>       


</form>

</div>

<?php include('footer.php'); ?>

</body>
</html>

Parse error: syntax error, unexpected 'class' (T_CLASS) in C:\xampp\htdocs\registration2.php on line 56

Where can I find the right phpmailer class:

line 56: require_once(‘phpmailer/class.phpmailer.php’); //memanggil library php mailernya

I already look for one but it's incorrect.

PHPMailer

It seems the encoding of your editor change it to UTF8, and replace ‘ and ’ with double quotes.

I fix the encoding thing, but now I cannot find the complete package of PHPMailerClass and it's other complementary files.

PHPMailerClass

It looks like now that I have to fix it one by one, like adding :

PHPMailerAutoload

Then, I have another error to fix like:

Fatal error: Class 'SMTP' not found in C:\xampp\htdocs\phpmailer\class.phpmailer.php on line 1202

line 1202 :

 if (!is_object($this->smtp)) {
            $this->smtp = new SMTP;
        }

Is there a complate PHPMailer Class like where it's all in one package?

Yes, it happens because you are linking directly to the phpmailer class, you have to require the autoload, so instead of:

require_once("phpmailer/class.phpmailer.php");

Do:

require $_SERVER['DOCUMENT_ROOT'] . '/phpmailer/PHPMailerAutoload.php';

AS written in the documentation:

PHPMailer provides an SPL-compatible autoloader, and that is the preferred way of loading the library - just require '/path/to/PHPMailerAutoload.php'; and everything should work.

ok, now I already replace:

require_once("phpmailer/class.phpmailer.php");

with:

require $_SERVER['DOCUMENT_ROOT'] . '/phpmailer/PHPMailerAutoload.php';

And I still have this error:

Fatal error: Class 'SMTP' not found in C:\xampp\htdocs\phpmailer\class.phpmailer.php on line 1202

Do you have class.smtp.php into the phpmailer directory?

ok, this time I get this message:

2014-08-21 13:22:01 SMTP ERROR: Failed to connect to server: (0) 2014-08-21 13:22:01 SMTP connect() failed. Your message has been sent, we will get back to your shortly.

failed to connect to SMTP. why is it?

It's probably generated by:

$mail->Host = "ssl://smtp.indonusa.net.id";

does ssl listen on port 25?

This line:

$mail->Host = "ssl://smtp.indonusa.net.id";

...should not contain ssl:// at the beginning. I'm fairly certain it should simply be:

$mail->Host = "smtp.indonusa.net.id";

If not, specity http:// at the beginning. The reason I believe you don't need it is because this line:

$mail->SMTPSecure = '';

...is what determines if it uses an SSL connection or a standard connection.

@Borzoi

at first I thought the same, but it is not correct, check the comments in the source code:

The $mail->Host can be expressed in different ways, even multiple fallback smtp servers:

smtp.domain.tld:25
ssl://smtp.domain.tld:25
ssl://smtp1.domain.tld:465,smtp2.domain.tld:25

Just trying to confirm:
you do understand that

  1. windows xampp wamp et al do not include mail servers
  2. The resources linked to refer to linux and windows xp not windows 2012 systems.

  3. That external mail servers require authentication not included in any of the scripts so far shown

The method for accessing an smtp host is very similar to accessing your sql DB server
Server, Port, Name, password, are all required
Borzoi is correct;
Usually the hosts are 'smtp.server.com'
the protocol is taken care of by other declarations,
what the instructions say you can and
what best practice says you should
are way different

You can jump off a 1000 foot cliff,
but you probably shouldn't, and you cant do it twice.

REQUIRED pop and smtp server connection details will likely be in the Host's helpscreens

@almostbob

Usually the hosts are 'smtp.server.com' the protocol is taken care of by other declarations, what the instructions say you can and what best practice says you should are way different

You can jump off a 1000 foot cliff, but you probably shouldn't, and you cant do it twice.

Hi, you are correct, but the value refers to the socket opened by the library, which allows the above syntax.

At the end the connection will be executed by line 1332:

if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options))

This is the linked documentation:

/**
 * SMTP hosts.
 * Either a single hostname or multiple semicolon-delimited hostnames.
 * You can also specify a different port
 * for each host by using this format: [hostname:port]
 * (e.g. "smtp1.example.com:25;smtp2.example.com").
 * You can also specify encryption type, for example:
 * (e.g. "tls://smtp1.example.com:587;ssl://smtp2.example.com:465").
 * Hosts will be tried in order.
 * @type string
 */
public $Host = 'localhost';

Link:

Then check:

Which is where the string is verified. By using the above you override the default settings.

Maybe I'm wrong, but I think the issue here is given by the port number for the ssl connection. Bye!

allows, does not mean should, port numbers for ssl connections may be 25, but are ofter 465 585
The host should have the ports on its setup helpscreens

Probably not, but the instruction guide me to place ssl:// before I input the smtp name.

ok, I'll try removing the ssl:// and this message what I get:

2014-08-21 22:38:07 SERVER -> CLIENT: 220 EHUB3.idcloud.biz Microsoft ESMTP MAIL Service ready at Fri, 22 Aug 2014 05:38:08 +0700 2014-08-21 22:38:07 CLIENT -> SERVER: EHLO www.squprime.com 2014-08-21 22:38:07 SERVER -> CLIENT: 250-EHUB3.idcloud.biz Hello [202.93.143.156] 250-SIZE 30720000 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH 250-8BITMIME 250-BINARYMIME 250 CHUNKING 2014-08-21 22:38:07 CLIENT -> SERVER: AUTH LOGIN 2014-08-21 22:38:12 SERVER -> CLIENT: 504 5.7.4 Unrecognized authentication type 2014-08-21 22:38:12 SMTP ERROR: AUTH command failed: 504 5.7.4 Unrecognized authentication type 2014-08-21 22:38:12 CLIENT -> SERVER: QUIT 2014-08-21 22:38:12 SERVER -> CLIENT: 221 2.0.0 Service closing transmission channel 2014-08-21 22:38:12 SMTP connect() failed. Your message has been sent, we will get back to your shortly.

Ok, this is a problem:

2014-08-21 22:38:07 CLIENT -> SERVER: AUTH LOGIN
2014-08-21 22:38:12 SERVER -> CLIENT: 504 5.7.4 Unrecognized authentication type

You send AUTH LOGIN as authentication type, but there are different methods supported by PHPMailer (line 311 & 274):

PLAIN, LOGIN, NTLM, CRAM-MD5

That can be set by the AuthType property, for example:

$mail->AuthType = 'NTLM';

The default value is LOGIN, check the documentation about your SMTP server.

Yes, it happens because you are linking directly to the phpmailer class, you have to require the autoload
Thanks for

ok, then which authentication type should I use?

My smtp server is smtp.indonusa.net.id and someone mention that I have to use user & password which I already include in my coding:

$mail->AuthType = 'NTLM';

$mail->Username = "davy@indonusa.net.id"; //username email

$mail->Password = "*********"; //password email

This message that I get (other login authentication type besides NTLM gives authentication error message):

2014-08-22 04:43:51 SERVER -> CLIENT: 220 EHUB3.idcloud.biz Microsoft ESMTP MAIL Service ready at Fri, 22 Aug 2014 11:43:50 +0700 2014-08-22 04:43:51 CLIENT -> SERVER: EHLO www.squprime.com 2014-08-22 04:43:51 SERVER -> CLIENT: 250-EHUB3.idcloud.biz Hello [202.93.143.156] 250-SIZE 30720000 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH 250-8BITMIME 250-BINARYMIME 250 CHUNKING
Warning: require_once(extras/ntlm_sasl_client.php): failed to open stream: No such file or directory in C:\xampp\htdocs\phpmailer\class.smtp.php on line 364

Fatal error: require_once(): Failed opening required 'extras/ntlm_sasl_client.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\phpmailer\class.smtp.php on line 364

---------------------------------
class.smtp.php

line 364: require_once 'extras/ntlm_sasl_client.php';

Include the extras directory into phpmailer/. That solves the require_once error. Then retry.

ok, then which authentication type should I use?

If in doubt ask to the mail server admin.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.