create wsdl for sending email using soap and php
--------------------------create wsdl using my code simple php --------------------------------------------
<?php Author by bikash ranajn nayak
require_once('../lib/nusoap.php');
$server = new nusoap_server;
$server->configureWSDL('server', 'urn:server');
$server->wsdl->schemaTargetNamespace = 'urn:server';
$server->wsdl->addComplexType('Emailsend','complexType','struct','all','',
array(
'To' => array('name' => 'ToEmailid','type' => 'xsd:int'),
'From' => array('name' => 'FromEmailid','type' => 'xsd:string'),
'Subject' => array('name' => 'Subject','type' => 'xsd:string'),
'Message' => array('name' => 'MessageBody','type' => 'xsd:string')
));
$server->register('Emailsend',
array('servicebybikash' => 'xsd:string'),
array('return' => 'xsd:string'),
'urn:server',
'urn:server#functions');
function Emailsend($to,$from,$subject,$messagebody)
{
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
if(mail($to,$subject,$messagebody,$headers)){
return true;
}else{
return false;
}
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
---------------------------------------call wsdl service using php soap------------------------------------
create a page call the wsdl service using php
<?php
/*
* auther by bikash
*
* Client sample.
*
* Service: SOAP endpoint
* Payload: rpc/encoded
* Transport: http
* Authentication: none
*/
require_once('../lib/nusoap.php');
$client = new soapclient('http://bikashnayak.com/samples/index.php?wsdl');
$htmldbody="<h1>helow bikash kese ho</h1>";
$res=$client->__call('Emailsend',array('to'=>'bikash@techwave.com','from'=>'shamim@techwave.com','helo i shamaim',$htmldbody));
if($client->fault)
{
echo "Fault: <p>Code: {$client->faultcode}<br>";
echo "String: {$client->faultstring}";
}
else
{
echo '<pre>' . htmlspecialchars($client->return, ENT_QUOTES) . '</pre>';
echo "success fully sent mail";
}
?>
Comments
Post a Comment