Solved

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

Posted on 2013-12-12
7
2,219 Views
Last Modified: 2013-12-12
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
Comment
Question by:Sqlspider
  • 3
  • 3
7 Comments
 
LVL 20

Expert Comment

by:carlmd
ID: 39714401
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
 

Author Comment

by:Sqlspider
ID: 39714447
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
 
LVL 20

Accepted Solution

by:
carlmd earned 180 total points
ID: 39714478
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:Sqlspider
ID: 39714533
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
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 120 total points
ID: 39714582
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
 
LVL 20

Assisted Solution

by:carlmd
carlmd earned 180 total points
ID: 39714585
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
 

Author Closing Comment

by:Sqlspider
ID: 39714957
Thank you both for your help in this.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Lync server 2013 Backup Service Error ID 4049 – After File Share Migration
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now