Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2484
  • Last Modified:

Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable to relay

Good Day to all!

I am trying to resolve an issue when trying to send mail via PHP.  Here is my test script
<?php
$to = "name@domain.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "name@domaincom";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?> 

Open in new window


In the PHP.ini here is the following:

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = 192.x.x.x
; http://php.net/smtp-port
smtp_port = 1677
Is what is in the old php.ini

Open in new window


I had believed that the smtp_port should be equal to port 25.  Am I wrong.

What am I missing here.  Can I also specify in my PHP code the server and port?

Thanks

SqlSpider
0
Sqlspider
Asked:
Sqlspider
  • 3
  • 3
3 Solutions
 
carlmdCommented:
This error means that your mail server is rejecting the relay mail as unauthorized. Depending upon (what) your mail serveris, there is usaually a file or place where you can indicate those hosts that are authorized for mail relay. You need to add the name/ip address of the system you are running the php script on to that file or setting.

Yes the smtp port is 25.
0
 
SqlspiderAuthor Commented:
Thank you kindly Carlmd.  Please if I may ask just to appease the CIO that works here. Is there a way for me to in the code below put in the smtp server address and port 25 to prove to him that the issue is when he changed to port 1677 or will 1677 work?  This was not a problem until he changed the port from 25 to 1677.


<?php
$to = "mrichardson@biz-med.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "mrichardson@biz-med.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?> 

Open in new window



Thanks
0
 
carlmdCommented:
You can't just change the smtp port in the php code. The smtp server listens on port 25 by default. You must change (reconfigure) that server to listen on port 1677 instead, if that is what you want. If this is the smtp server that services yor entire office then no one will be able to send mail unless they reconfigure their mail software (outlook?) to use that port instead of 25.

What is it that you are trying to accomplish by changing the port?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
SqlspiderAuthor Commented:
I understand you entirely it is my CIO that does not listen to reason.  He changed the php.ini on the webserver to point the smtp server port to 1677.  I explained that this will stop all mail in php from being delivered.  And it surely has.  He does not believe that is the issue so in my trying to prove a point i need to show him that in my code I supplied here that if he changes the port back to 25 all of the PHP's that are using that smtp server to send mail will start to work again.

It is truly political.  So in my code can I hardcode the smtp servername and port forcing it to bypass the php.ini file and send the mail so I can show him that he has changed this in error and before there are more delays put the point back to 25.  Trust me I understand everything you stated I am trying to prove to him but my knowledge to hardcode this in my test php is limited. so I needed help with that or even documentation showing he is in error.  I looked on php.net but could not find a good enough explaination that is concise and to the point.
0
 
Ray PaseurCommented:
Install this, put your own URL at line 9, check line 59, and then run it.  The results may be helpful.

<?php // RAY_monitor_website.php
error_reporting(E_ALL);


// DEMONSTRATE HOW AN INDIVIDUAL WEB SITE MONITOR WORKS


// A WEB SITE TO MONITOR - THIS COULD COME FROM THE URL VIA $_GET
$url = 'www.landonbaseball.com';

// THE TIME TO ALLOW FOR CONNECTION
$timex = 1;


// REPORT WHAT HAPPENED IN EASY-TO-READ FORMAT
$resp = "<pre>";
$resp .= "URL: <b>$url</b> TIME: $timex";


// TEST HTTP(S) WWW RESPONSE WITH CURL
$x = my_curl('http://' . $url . '/anything_will_do_here');
if (!$x)
{
    $resp .= PHP_EOL . "HTTP Response: FAIL";
}
else
{
    $resp .= PHP_EOL . "HTTP Response {$x[0]}";
}

$x = my_curl('https://' . $url . '/anything_will_do_here');
if (!$x)
{
    $resp .= PHP_EOL . "HTTPS Response: FAIL";
}
else
{
    $resp .= PHP_EOL . "HTTPS Response {$x[0]}";
}
$resp .= PHP_EOL;


// COMMONLY USED PORT NUMBERS
// SEE: http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xml (SLOW TO LOAD)
// SEE: http://browntips.com/cpanel-and-whm-port-numbers/
$ports["HTTP"]     =    80;
$ports["FTP"]      =    21;
$ports["SSH"]      =    22;
$ports["TELNET"]   =    23;
$ports["SMTP"]     =    25;
$ports["DNS"]      =    53;
$ports["MYSQL"]    =  3306;
$ports["CPANEL"]   =  2082;
$ports["CPANEL-S"] =  2083;
$ports["WHM"]      =  2086;
$ports["WHM-S"]    =  2087;
$ports["POP3"]     =   110;
$ports["IMAP"]     =   143;
$ports["STRANGE"]  =  1677;

// THE RESULTS SET
$errno = $errstr = array();

// TEST EACH OF THE PORTS - SEE http://php.net/manual/en/function.fsockopen.php
foreach ($ports as $port_name => $port_number)
{
    $fp
    = @fsockopen // @MAKE ERRORS SILENT
    ( $url
    , $port_number
    , $errno[$port_name]
    , $errstr[$port_name]
    , $timex
    )
    ;
}

// ADD THE PORT TESTS TO THE RESPONSE STRING
foreach ($errno as $port_name => $error_number)
{
    if (!$error_number)
    {
        $resp .= PHP_EOL . "OK: $port_name $ports[$port_name]";
    }
    else
    {
        $resp .= PHP_EOL . "ERROR $error_number: $port_name $errstr[$port_name] ON PORT $ports[$port_name]";
    }
}


// SHOW THE WORK PRODUCT
echo $resp;


// A FUNCTION TO RUN A CURL-GET CLIENT CALL TO A FOREIGN SERVER
function my_curl($url, $timeout=1, $error_report=FALSE)
{
    $curl = curl_init();

    // HEADERS AND OPTIONS APPEAR TO BE A FIREFOX BROWSER REFERRED BY GOOGLE
    $header[] = "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
    $header[] = "Cache-Control: max-age=0";
    $header[] = "Connection: keep-alive";
    $header[] = "Keep-Alive: 300";
    $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
    $header[] = "Accept-Language: en-us,en;q=0.5";
    $header[] = "Pragma: "; // BROWSERS USUALLY LEAVE BLANK

    // SET THE CURL OPTIONS - SEE http://php.net/manual/en/function.curl-setopt.php
    curl_setopt( $curl, CURLOPT_URL,            $url  );
    curl_setopt( $curl, CURLOPT_USERAGENT,      'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'  );
    curl_setopt( $curl, CURLOPT_HTTPHEADER,     $header  );
    curl_setopt( $curl, CURLOPT_REFERER,        'http://www.google.com'  );
    curl_setopt( $curl, CURLOPT_ENCODING,       'gzip,deflate'  );
    curl_setopt( $curl, CURLOPT_AUTOREFERER,    TRUE  );
    curl_setopt( $curl, CURLOPT_RETURNTRANSFER, TRUE  );
    curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, TRUE  );
    curl_setopt( $curl, CURLOPT_TIMEOUT,        $timeout  );

    // RUN THE CURL REQUEST AND GET THE RESULTS
    $htm = curl_exec($curl);
    $htc = curl_getinfo($curl, CURLINFO_HTTP_CODE);

    // ON FAILURE HANDLE ERROR MESSAGE
    if ($htm === FALSE)
    {
        if ($error_report)
        {
            $err = curl_errno($curl);
            $inf = curl_getinfo($curl);
            echo "CURL FAIL: $url TIMEOUT=$timeout, CURL_ERRNO=$err";
            var_dump($inf);
        }
        curl_close($curl);
        return FALSE;
    }

    // ON SUCCESS RETURN XML / HTML STRING
    curl_close($curl);
    return array($htc, $htm);
}

Open in new window

0
 
carlmdCommented:
This is not a php issue but rather a mail sending issue. You are using a standard service to send mail, and it does not know about port 1677.

If you need to see the port specification in writing look at:

http://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol

To prove this just edit the php.ini file and chaneg 1677 back to 25.
0
 
SqlspiderAuthor Commented:
Thank you both for your help in this.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now