Hi ,
i'm in trouble with sending emails via SOAP.
i've done the Class ( that works perfect if included ), than generated
the wsdl ( that responds with the right methods ) and the Client that
makes Calls.
If I run the Client i've back nothing in debugger neither in other place.
I'm not sure but i think that the $_SERVER call in the __construct is
not ok , is it righht ?
Sorry for my poor english and Thanks for any help.
Matteo
this is the SoapServer:
###################################################
<?php
class service_sendmail {
public $message = null;
public $to_email = null;
public $to_name = null;
public $cc_email = null;
public $cc_name = null;
public $bcc_email = null;
public $bcc_name = null;
public $subject=null;
public $msg_ok=null;
protected $messaggio=null;
private $url_origine=null;
private $name=null;
private $email=null;
public function __construct(){
/**
* retrieve dell'host che vuole inviare una mail
*/
$this->url_origine=$this->hostchiamante();
}
private function hostchiamante(){
/**
* l'url che sta chiedendo di inviare una mail
*/
$stringa_url=$_SERVER['HTTP_HOST'];
$name_url=explode('/',str_ireplace('http://','',$stringa_url));
return $name_url[0];
}
private function query_autenticazione($url_chiamante){
require_once 'Zend/Db.php';
// Automatically load class Zend_Db_Adapter_Pdo_Mysql and create an
instance of it.
$db_soap = Zend_Db::factory('Pdo_Mysql', array(
'host' => '127.0.0.1',
'username' => 'XX',
'password' => 'XX',
'dbname' => 'XX'
));
$sql_soap="select URL, nome_cognome, email from soap where URL=?";
$to_bind=array($url_chiamante);
$result = $db_soap->fetchAll($sql_soap, $to_bind);
$this->nome=$result[0]['nome_cognome'];
$this->email=$result[0]['email'];
return $result;
}
private function invia(){
require_once 'Zend/Mail.php';
$mail = new Zend_Mail();
$mail->setBodyText($this->messaggio);
$mail->setFrom($this->email, $this->nome);
$mail->addTo($this->to_email,$this->to_name);
$mail->addCc($this->cc_email,$this->cc_name);
$mail->addBcc($this->bcc_email, $this->bcc_name);
$mail->setSubject($this->subject);
$mail->send();
}
public function crea_messaggio(){
$array_val=$this->query_autenticazione($this->url_origine);
$status=count($array_val);
switch ($status){
case 0:
/**
* 0 risultati non puo' inviare manca la registrazione
*/
$messaggio="L'URL ".$this->url_origine." non puo' inviare emails";
//echo "no!";
break;
case 1:
/**
* il risultato della query va bene
* c'è qualcosa
*/
$output=$this->query_autenticazione($this->url_origine);
$this->invia();
$messaggio=$this->msg_ok;
break;
}
$this->invia();
echo "ok";
echo $messaggio;
//return $messaggio;
}
}
$sendmail = new
SoapServer('http://soap.sitonerd.com/service_sendmail.wsdl');
$sendmail->setClass("service_sendmail");
$sendmail->handle();
try {
// this works
$service = new service_sendmail();
$service->messagge="test";
$service->to_name="matteo";
$service->to_email="matteo@cisilino.com";
$service->msg_ok="fatto";
$service->crea_messaggio();
}
catch (SoapFault $e){
print_r($e);
}
?>
##########################################################
this is the wsdl
##########################################################
<?xml version='1.0' encoding='UTF-8'?>
<!-- WSDL file generated by Zend Studio. -->
<definitions name="simple_email" targetNamespace="urn:simple_email"
xmlns:typens="urn:simple_email"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<message name="__construct"/>
<message name="__constructResponse"/>
<message name="invia"/>
<message name="inviaResponse"/>
<portType name="simple_emailPortType">
<operation name="__construct">
<input message="typens:__construct"/>
<output message="typens:__constructResponse"/>
</operation>
<operation name="invia">
<input message="typens:invia"/>
<output message="typens:inviaResponse"/>
</operation>
</portType>
<binding name="simple_emailBinding" type="typens:simple_emailPortType">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="__construct">
<soap:operation soapAction="urn:simple_emailAction"/>
<input>
<soap:body namespace="urn:simple_email" use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body namespace="urn:simple_email" use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="invia">
<soap:operation soapAction="urn:simple_emailAction"/>
<input>
<soap:body namespace="urn:simple_email" use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body namespace="urn:simple_email" use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="simple_emailService">
<port name="simple_emailPort" binding="typens:simple_emailBinding">
<soap:address location="http://soap.sitonerd.com/simple_email.php"/>
</port>
</service>
</definitions>
####################################################################
this is a simple client
###################################################################
<?php
ini_set("soap.wsdl_cache_enabled" , "0");
ini_set("error_reporting", "E_ALL");
try {
$service = new SoapClient("http://soap.sitonerd.com/service_sendmail.wsdl");
$service->messagge="test";
$service->to_name="matteo";
$service->to_email="mail@example";
$service->msg_ok="fatto";
$service->crea_messaggio();
}
catch (SoapFault $e){
print_r($e);
}
?>
--
PHP Soap Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php