I have followed the instructions of the mailgun, including dots and commas. I installed composer successfully. My domain name is also verified so I wanted to use API for sending emails.
I created a simple application for testing if emails are going or not.
here is the code of sample php application:
<?php
require 'vendor/autoload.php';
use Mailgun\Mailgun;
$mg = new Mailgun("key-********************************");
$domain = "https://api.mailgun.net/v3/mailgun.************.com/messages";
$mg->sendMessage($domain,
array(
'from' => 'noreply#********.com',
'to' => '********#hotmail.com',
'subject' => 'The mailgun is awesome!',
'text' => 'It is so simple to send a message.'));
echo "done";
?>
I get internal server error 500 when I run this file.
When I change the $domain to "mailgun.*****.com" I get emails but in junk folder
I am confused what is happening here.. no apparent fault..
May be some expert will be able to help me out here..
The $domain has to be the same as entered in your settings.
i.e. the domain is mg.domain.com in your mailgun account,
your $domain is domain.com.
Also your from has to be [anything]#domain.com, to be accepted.
Related
I try to get from PHP the information about the currently connected clients.
http://10.0.0.2:8000/admin/listclients?mount=/stream.mpeg
but this required an authenfication, which is not possible from a program. So I tried
http://10.0.0.2:8000/admin/listclients?mount=/stream.mpeg&user=xyz&pass=wert
but Icecast does not accept the user and pass. If I do it inside a browser it works?
In which way I have to provide user and pass?
Or is some additional information required?
Google did not help me.
It's not possible to put user and pass directlyin the URL. These information has to be base64 encoded and put into the header. Below you find a php example:
$url = "http://www.domain.eu:80004/admin/listclients?mount=/stream.mpeg";
$user = "source";
$pass= "password";
$opts = array('http' =>
array(
'method' => 'GET',
'header' => array ('Authorization: Basic '.base64_encode("$user:$pass"))
)
);
$context = stream_context_create($opts);
$list1 = file_get_contents($url1, false, $context);
You can use the admin password or the source password. I the example I have used the source password.
Building out a passwordless login system for a client using laravel. Wanting to make sure the following regex rule for email validation will only let users to submit an email address with that specific domain account...
'email' => 'required|email:rfc,dns,spoof|regex:/^.+#domain.com$/i',
More of a sanity check to make sure I am not missing or not thinking of something else that could be used to work around that.
Cheers
Citti
create a custom Laravel validation rule and use this snippet.
$email = 'shagtv#domain.com';
$domains = array('#domain.com');
$pattern = "/^[a-z0-9._%+-]+#[a-z0-9.-]*(" . implode('|', $domains) . ")$/i";
if (preg_match($pattern, $email)) {
echo 'valid';
} else {
echo 'not valid';
}
So I was trying to connect our SMS (Student Management System) to a government Service or Site. The process requires an authentication token coming from Vanguard. Successfully, I am able to obtain the token... but due to lack of documentation and sample codes in PHP I am having problem communicating to the said service. I was wondering if is it my code that causes the problem or is it my calls that has conflict interfacing to the webservice: Please see code below:
<?php
require_once 'VanguardClient.php';
$endpoint = 'https://3pt.portal.usi.gov.au/Service/v2/UsiService.svc';
function get_sts($endpoint){
$test = true;
$auskey_path = 'Keystore.xml';
$auskey_password = 'Password1!';
$v = new VanguardClient($test);
$v->loadAuskey($auskey_path, $auskey_password);
try {
return $v->requestToken($endpoint);
} catch (SoapFault $e) {
echo "Error1:";
echo $e;
}
}
//get token from Vanguard
$token = get_sts($endpoint);
//create soap client
try{
$wsdl = 'https://3pt.portal.usi.gov.au/service/V2/UsiService.wsdl';
$client = new SoapClient($wsdl,
array(
'trace' =>1,
//'soap_version' => SOAP_1_2,
'keep_alive' => false,
//'connection_timeout' => 500000,
'cache_wsdl' => WSDL_CACHE_NONE
)
);
} catch (SoapFault $e) {
echo "SoapClient Error:<br />";
var_dump($e);
}
try {
$result=$client->__setSoapHeaders( $token );
} catch (SoapFault $e) {
echo "__setSoapHeaders:";
var_dump($e);
}
$data = array(
'OrgCode' => '970003',
'USI' => 'U6Q8JN6UD9',
'FirstName' => 'Myrna',
'FamilyName' => 'Macknight',
'DateOfBirth' => '1971-04-19'
);
try{
$response=$client->__soapCall('VerifyUSI',$data);
} catch (SoapFault $e) {
echo "__soapCall Error:<br />";
echo $e;
}
var_dump($response);
The result on the browser that I am seeing is this:
SoapFault exception: [HTTP] Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'. in /var/www/html/usitest/example1.php:73 Stack trace: #0 [internal function]: SoapClient->__doRequest('__soapCall('VerifyUSI', Array) #2 {main}NULL
Thanks in advance guys!!!
Your content type is probably caused by the SOAP version.
Try setting the SOAP version to 1.2:
'soap_version' => SOAP_1_2
See SoapClient connection to SoapServer
However, I think there are other issues in your code - particularly with the Vanguard token.
We managed to solve this however it took many classes, templates, external packages and months of work to solve and is not something we can put up online. However there are some things I'd suggest you do to solve it in your situation.
This does not work like a normal SOAP service. Use XML templates for all steps of the various process (Vanguard, USI, components of these sections etc).
Reverse engineer the .Net example code, we had major issues with the Java code.
We made major headway by using a proxy and capturing the content sent and received.
Unless you are using composer to manage your security dependencies you're going to have a bad time, even with composer it was a pain.
There are about 10 sections to do with security that have to be reverse engineered, don't forget to canonicalise the content to get the encryption correct.
Use Guzzle for the requests, it's easier
Most of the stuff in the PHP example is wrong, or at least impossible to follow and debug to fix. At the end we couldn't see a way that it would work.
Expect to spend at least a couple of weeks on it and you need to know a lot about security, hashing and ssl certificates.
Sorry I can't give you a full working solution but knowing these steps above would have definitely helped us and so I hope they'll help you.
I want to use Mailgun in my Rails application.
When I include through Heroku addon it display error to add credit card number though I wanted the free version.
I looked up and found this code from Mailgun. Could someone tell me how to use it?
require 'mail'
Mail.defaults do
delivery_method :smtp, {
:port => 587,
:address => "smtp.mailgun.org",
:user_name => "",
:password => "",
}
end
mail = Mail.deliver do
to 'bar#example.com'
from 'foo#YOUR_DOMAIN_NAME'
subject 'Hello'
text_part do
body 'Testing some Mailgun awesomness'
end
end
I tried using this but it displays an error - mailgun SSL_read: sslv3 alert bad record mac
You need to sign up with Mailgun and get your SMTP username and password which you would use in the mail configuration.
i am using a php mail script to send mail, but when sent the user is getting Apache server has the from. How to remove apache server from the from header of a email.
<?php
//mail script
$to = 'email#email.com';
$subject = "Your welcome";
$header= "From: admin";
//other headers
$server = "email.com";
ini_set("SMTP, $server");
$message = "hello";
mail($to, $subject, $message, $headers);
?>
i have tried removing $server and ini_set line. when i do this i get domainname#servername.com.
Please take a look at the examples in the PHP manual, specifically example 4 on the mail page.
There are two issues in your script:
You're setting the $header variable, then using $headers in the mail function call.
The from header must contain an actual email address, and may optionally contain a name
It should be
$headers = 'From: Admin <admin#example.com>';
That will show the name Admin and have the email admin#example.com.