I am attempting to use PEAR to send email on a Fedora server machine and am getting nowhere.
Below is the code I am trying to use. The email authentication settings in the code are not the actual but the info I am using is pulled from my email client config so should work.
I am also trying to get debug info to find out what is happening. Is setting 'debug' to 'true' enough or is something else required? And where can I find the debug log information?
A lot of asks but I hope someone can direct me in the right direction.
I tried PHPMailer as well but no go. I have this sense that some configuration on the machine is blocking...
One more thing, this exact code works on a Ubuntu machine so I know it works. I am trying to move all services from the Ubuntu machine to a Fedora machine.
<?php
require_once "Mail.php";
$from = "demo#demo.com";
$recipients = 'demo#demo.com';
$headers["From"] = $from;
$headers["To"] = 'demo#demo.com';
$headers["Reply-To"] = $from;
$headers["Subject"] = 'Testing';
$headers["MIME-Version"] = "1.0";
$headers["Content-Type"] = "text/html; charset=UTF-8";
$body = 'Testing';
$smtpinfo["host"] = "mail.demo.com";
$smtpinfo["port"] = "587";
$smtpinfo["auth"] = true;
$smtpinfo["username"] = "demo#demo.com";
$smtpinfo["password"] = "password";
$smtpinfo["debug"] = true;
$mail_object = Mail::factory("smtp", $smtpinfo);
$mail_object->send($recipients, $headers, $body);
if (PEAR::isError($mail_object)) {
$ret['success'] = false;
$ret['msg'] = 'Message delivery failed...';
} else {
$ret['success'] = true;
$ret['msg'] = 'data is valid';
}
return $ret;
?>
Thank you
So, after a few more hours of testing I have resolved the issue. This website provided direction on how to get debug information in the command line.
After testing the PHP code from the command line and confirming that messages can be sent, I attempted to send an email from a web page; which failed to work.
So, now thinking that the issue is likely related to the web server, led me to this question on Stack Overflow . The solution of which resolved the issue immediately. Specifically, doing the following as described in the accepted solution:
$ sestatus -b | grep sendmail
httpd_can_sendmail off
$ restorecon /usr/bin/sendmail
$ setsebool -P httpd_can_sendmail 1
Hope this helps someone else facing the some problem.
Related
I am trying to send emails via PHP Mailer (upon it not working I also installed and tried Swift Mailer, and am getting the same results).
I can send them using localhost but it ALWAYS goes to spam, which is doing my head in. So I am trying to send it through SMTP through my gmail account, in the hope that this will help authenticate the email.
Here is my code:
function SendMail( $ToEmail, $MessageHTML, $MessageTEXT ) {
require_once ( '../phpmailer/PHPMailerAutoload.php' ); // Add the path as appropriate
$Mail = new PHPMailer();
$Mail->IsSMTP(); // Use SMTP
$Mail->Host = "smtp.gmail.com"; // Sets SMTP server
$Mail->SMTPDebug = 2; // 2 to enable SMTP debug information
$Mail->SMTPAuth = TRUE; // enable SMTP authentication
$Mail->SMTPSecure = "tls"; //Secure conection
$Mail->Port = 587; // set the SMTP port
$Mail->Username = 'b31tom#gmail.com'; // SMTP account username
$Mail->Password = 'workingpass'; // SMTP account password (IVE TRIED BOTH NORMAL AND APP PASSWORDS)
$Mail->Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$Mail->CharSet = 'UTF-8';
$Mail->Encoding = '8bit';
$Mail->Subject = 'Test Email Using Gmail';
$Mail->ContentType = 'text/html; charset=utf-8\r\n';
$Mail->From = 'b31tom#gmail.com';
$Mail->FromName = 'GMail Test';
$Mail->WordWrap = 900; // RFC 2822 Compliant for Max 998 characters per line
$Mail->AddAddress( $ToEmail ); // To:
$Mail->isHTML( TRUE );
$Mail->Body = "Test";
$Mail->AltBody = "Test";
$Mail->Send();
$Mail->SmtpClose();
if ( $Mail->IsError() ) { // ADDED - This error checking was missing
return FALSE;
}
else {
return TRUE;
}
}
$ToEmail = 'b31tom#me.com';
$ToName = 'Name';
$Send = SendMail( $ToEmail, $MessageHTML, $MessageTEXT );
if ( $Send ) {
echo "<h2> Sent OK</h2>";
}
else {
echo "<h2> ERROR</h2>";
}
die;
This returns the following error:
2014-12-16 13:17:14 SMTP ERROR: Failed to connect to server: Network is unreachable (101) 2014-12-16 13:17:14 SMTP connect() failed.
ERROR
I have contacted my web provider to check the following:
OpenSSL enabled
fopen enabled
ports 465 and 587 open
I have gone through numerous example codes from both PHP Mailer and Swift Mailer (which all claim to be working code!) and all give the same result. Normally the error 101 cannot connect to the gmail server!
I currently have a support ticket open with my web provider and have people looking into it there and they can't see an issue either.
Help please :(
Right at this moment, gmail smtp servers appear to be having widespread outages this morning. I don't know code:) but was searching for others having issues. Re-try later.
Thanks for your help. My web provider enabled the pfsockopen function in a local php.ini and it fixed the issue.
I hope this helps any one in the future.
From the command line I can successfully connect via FTP to my host using either
ftp.domain.com or domain.com
C:\Users\Aaron>ftp
ftp> open
To domain.com
Connected to domain.com.
220 FTP Server ready.
User (domain.com:(none)): Login failed.
ftp> close
221 Goodbye.
ftp> open
To ftp.domain.com
Connected to ftp.domain.com.
220 FTP Server ready.
User (ftp.domain.com:(none)): Login failed.
ftp> close
221 Goodbye.
ftp> quit
I escaped entering the password above and scrubbed the domain, but it still shows for each connection I was successful. When I run this code in Visual studio, I get the invalid URI.
Here is my code I've tried in C#
Uri target = new Uri("ftp://ftp.domain.com/");
FtpWebRequest requestDir = (FtpWebRequest)FtpWebRequest.Create(target);
requestDir.Credentials = new NetworkCredential("user", "pass");
Uri target = new Uri("ftp://ftp.domain.com/");
FtpWebRequest requestDir = (FtpWebRequest)FtpWebRequest.Create(target);
requestDir.Credentials = new NetworkCredential("user", "pass");
The requested URI is invalid for this FTP command
I've looked on here as there are many like this, but I've tried all of them (I think) and I just keep on getting this error. Any ideas?
Thanks!
I was able to get it working with the help of some other posts here and a lot of troubleshooting. I now have this working and have moved on to new errors. Here is the code for the successful FTP upload:
reqCakes = (FtpWebRequest)WebRequest.Create("ftp://domain.com/images/" + "koala.jpg");
reqCakes.UseBinary = true;
reqCakes.Method = WebRequestMethods.Ftp.UploadFile;
reqCakes.Credentials = new NetworkCredential("user", "pass");
BinaryReader rdrCakes = new BinaryReader(File.Open(fileToOpen, FileMode.Open));
rdrCakes.Close();
byte[] cakeData = File.ReadAllBytes(fileToOpen);
reqCakes.ContentLength = cakeData.Length;
Stream reqStream = reqCakes.GetRequestStream();
reqStream.Write(cakeData, 0, cakeData.Length);
reqStream.Close();
While I´ve been trying to make the basic notification hub tutorial work on my Windows Phone solution with the following code
var channel = HttpNotificationChannel.Find("MyPushChannel3");
if (channel == null)
{
channel = new HttpNotificationChannel("MyPushChannel3");
channel.Open();
channel.BindToShellToast();
}
channel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(async (o, args) =>
{
var hub = new NotificationHub("http://messaging-ns.servicebus.windows.net/messagingt", "---MY CONECTION STRING---");
await hub.RegisterNativeAsync(args.ChannelUri.ToString());
});
I get a NotificationHubNotFoundException in the await line with the following message
HTTP request failed.
HTTP Details:
Status: 404
Reason: Not Found
Full content: 404No service is hosted at the specified address..TrackingId:2e4b1100-18de-4b24-bbec-68516ddc3b60_G4,TimeStamp:2/2/2014 1:30:23 AM
I tried a number of options for the first parameter of the NotificationHub constructor called "notificationHubPath" with no luck to get my app registered. Anyone has faced this error in the past. Unfortunately there are not enough documentation in how does this constructor works in MDSN.
Thanks
When creating the NotificationHub type object, try by passing just the hub name with the connection string, not the whole address:
var hub = new NotificationHub("messagingt", "---CONECTION STRING---");
I had the same issue, and after close/open VS2013, restart PC and change Wifi/3g connection it worked again like before... strange, i suppose that was a internet connection issue.
you can use fiddler to show more information, i forgot in my case...
I just downloaded PHP-EWS, installed following the README instructions, and spun up a script to test out its functionalities. When I try running the script in my browser, I get the following message:
I get the same message when I supply a login I know is invalid. It seems I am connecting to my Exchange server, but it's not recognizing the credentials I provide.
Here is the script I am using
<?php
function __autoload($className)
{
$className = str_replace('_','/', $className);
$sFileName = $className . '.php';
if (file_exists($sFileName) && !class_exists($className))
{
require_once $sFileName;
}
// If the above if fails, you're program will terminate, there is no way to catch this.
}
include("ExchangeWebServices.php");
$host = "https://myexchange/EWS/Services.wsdl";
$username = "myusername#mydomain.com";
$password = "mypassword";
$ews = new ExchangeWebServices($host, $username, $password);
$request = new EWSType_FindItemType();
$request->ItemShape = new EWSType_ItemResponseShapeType();
$request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::DEFAULT_PROPERTIES;
$request->Traversal = EWSType_ItemQueryTraversalType::SHALLOW;
$request->ParentFolderIds = new EWSType_NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType();
$request->ParentFolderIds->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::INBOX;
// sort order
$request->SortOrder = new EWSType_NonEmptyArrayOfFieldOrdersType();
$request->SortOrder->FieldOrder = array();
$order = new EWSType_FieldOrderType();
// sorts mails so that oldest appear first
// more field uri definitions can be found from types.xsd (look for UnindexedFieldURIType)
$order->FieldURI->FieldURI = 'item:DateTimeReceived';
$order->Order = 'Ascending';
$request->SortOrder->FieldOrder[] = $order;
$response = $ews->FindItem($request);
echo '<pre>'.print_r($response, true).'</pre>';
?>
Try testing your access by:
Hitting the server url directly: https://YOUREXCHANGESERVER/EWS/Services.wsdl
You should be prompted for credentials. After you enter your credentials you will be presented with the WSDL definition. If it does not present you a WSDL definition that looks like the example below then check with your administrator on credentials or if there are any firewall blocks put in place.
Example (Partial response):
<wsdl:definitions targetNamespace="http://schemas.microsoft.com/exchange/services /2006/messages"><wsdl:types><xs:schema><xs:import namespace="http://schemas.microsoft.com/exchange/services/2006/messages" schemaLocation="messages.xsd"/></xs:schema></wsdl:types>
A great tool I use in analyzing web services is: SOAP-UI by SmartBear
I can't get my Yahoo! Application Platform to run I keep getting denied access even though their policy file accepts requests from any domain.
OK: Policy file accepted: http://social.yahooapis.com/crossdomain.xml
Error: Request for resource at http://social.yahooapis.com/v1/user/<user id>/profile?oauth_signature_method=HMAC-SHA1&lang=en-US&oauth_consumer_key=<key>&oauth_token=<long ass token>&oauth_version=1.0&format=json&oauth_nonce=<blah blah>&oauth_timestamp=1262846353®ion=US&oauth_signature=<foo bar> by requestor from http://<my domain>/YOSSimple.swf is denied due to lack of policy file permissions.
The url works btw, I editted some stuff out since it has my keys and stuff.
Links to the stuff I'm trying to do
http://developer.yahoo.com/flash/yos/
http://developer.yahoo.com/flash/yos/examples/simple/YOSSimple.fla
YOSSimple properly creates the url actually since if I type it in my browser I'm prompted if I want to download the file that contains information regarding my profile.
But it just wont open it in Flash.
I'm guessing that it's not loading the policy file automatically. You should try using
Security.loadPolicyFile("http://social.yahooapis.com/crossdomain.xml");
Do you have a webproxy installed with which you can monitor what files exactly are loaded? My favorite is Charles but there are also free FF plugins like Httpfox
EDIT:
I think I know what's going wrong. It's going wrong the other way around, the swf from yahoo is trying to access your swf, but doesn't have the correct permissions. Would you try
Security.allowDomain( 'http://social.yahooapis.com/' );
http://www.ieinspector.com/httpanalyzer/
use HTTP analyzer to see whats happening?
also check your not missmatching http://www. with http:// because flash treats them as different domains
also are you running the code locally on your machine. It could be your local security settings
A simple WebProxy will fix this:
<?php
// PHP Proxy
// Loads a XML from any location. Used with Flash/Flex apps to bypass security restrictions
// usage: proxy.php?url=http://mysite.com/myxml.xml
$session = curl_init($_GET['url']); // Open the Curl session
curl_setopt($session, CURLOPT_HEADER, false); // Don't return HTTP headers
curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // Do return the contents of the call
$xml = curl_exec($session); // Make the call
header("Content-Type: text/xml"); // Set the content type appropriately
echo $xml; // Spit out the xml
curl_close($session); // And close the session
?>
Modify the web proxy example above to support multiple options as follows:
$sOptions = "";
foreach($_GET as $sIndex => $sValue) {
if ($sIndex == 'url') {
$url = $sValue;
}
else {
if (strlen($sIndex) > 0) {
$sOptions .= "&" . $sIndex;
}
if (strlen($sValue) > 0) {
$sOptions .= "=" . $sValue;
}
}
}
$url .= $sOptions;
$session = curl_init($url); // Open the Curl session