首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果第一个函数使用php成功,如何执行第二个函数

如果第一个函数使用php成功,如何执行第二个函数
EN

Stack Overflow用户
提问于 2015-03-17 20:03:53
回答 2查看 32关注 0票数 0

您好,我有一个php页面,使一个帖子使用网络服务,也在页面上,我应该发送一个电子邮件警报,如果通过网络服务的帖子是成功的,我的数据是成功地通过网络服务和电子邮件警报发送,但我注意到,当有一个错误和网络服务的时间帖子,我的电子邮件警报仍然发送,我知道这是非常错误的。

这就是我尝试过的

我的code服务代码

代码语言:javascript
复制
<?php


    // code to post data here
    require_once('includes/nusoap.php');

$wsdlfile = "https://niid.autoreglive.org/nia_api/service.asmx?wsdl";
$wsdlfile = "https://www.niid.org/NIA_API/Service.asmx?wsdl";

//$wsdlfile = "http://localhost:82/cscart/service/index.php";

 $msg = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>
<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">
<Username>j####.Ukwueze</Username>
<Password>Japh</Password>
<NiaNaicomID>nnn</NiaNaicomID>
<PolicyNo>TP/1/1</PolicyNo>
<InsuredName>Sunky Yaki</InsuredName>
<ContactAddress>Yaba Lagos</ContactAddress>
<GSMNo>08021231234</GSMNo>
<Email>a@b.c</Email>
<EffectiveCoverDate>2013-09-20</EffectiveCoverDate>
<ExpirationDate>2014-09-19</ExpirationDate>
<TypeOfCover>Comprehensive</TypeOfCover
><VehicleCategory>Saloon</VehicleCategory>
<EngineNo>uhdu</EngineNo>
<ChasisNo>dksdj</ChasisNo>
<VehicleColor>green</VehicleColor>
<YearofMake>1999</YearofMake>
<VehicleMake>Toyota</VehicleMake>
<RegistrationNo>gg11jj</RegistrationNo>
<OldRegistrationNo>11122</OldRegistrationNo>
<VehicleType>Saloon</VehicleType>
<EngineCapacity>4</EngineCapacity>
<VehicleModel>Camry</VehicleModel>
<SumAssured>233300</SumAssured>
<Premium>230</Premium>
<CoverNoteNo>1211</CoverNoteNo>
<CertificateNo>test 2</CertificateNo>
<GeographicalZone>North East</GeographicalZone>
</soap:Envelope>
 ";

 $Username = 'kbl';
$Password = 'kb@@@@'; 
$NiaNaicomID = 'NIA000'; 
$PolicyNo = $_POST['Policy_Number']; 
$InsuredName = $_POST['Insured_Name'];
$ContactAddress = $_POST['Residential_Address']; 
$GSMNo = $_POST['Telephone']; 
$Email = $_POST['Email'];
$EffectiveCoverDate = $_POST['Date'];
$ExpirationDate = $_POST['Date_Expiry'];
$TypeOfCover = $_POST['Type_Of_Insurance']; 
$VehicleCategory = 'null'; 
$EngineNo = $_POST['Engine_Number']; 
$ChasisNo = $_POST['Chassis_Number'];
$VehicleColor = $_POST['Colour']; 
$YearofMake = '2004'; 
$VehicleMake = $_POST['Make_Of_Car']; 
$RegistrationNo = $_POST['Registeration_Number']; 
$VehicleType = $_POST['Vehicle_Class']; 
$EngineCapacity = ''; 
$VehicleModel = 'Model'; 
$SumAssured = 2.3; 
$Premium = '2.3'; 
$CoverNoteNo = 'No note';
$CertificateNo = 'No certificate No';
$GeographicalZone = '6';

$params = array('Username' => $Username, 
                                                           'Password' => $Password, 
                                                           'NiaNaicomID' => $NiaNaicomID,
                                                           'PolicyNo' => $PolicyNo,
                                                           'InsuredName' => $InsuredName,
                                                           'ContactAddress' => $ContactAddress, 
                                                           'GSMNo' => $GSMNo, 
                                                           'Email' => $Email,
                                                           'EffectiveCoverDate' => $EffectiveCoverDate,
                                                           'ExpirationDate' => $ExpirationDate,
                                                           'TypeOfCover' => $TypeOfCover,
                                                           'VehicleCategory' => $VehicleCategory, 
                                                           'EngineNo' => $EngineNo, 
                                                           'ChasisNo' => $ChasisNo,
                                                           'VehicleColor' => $VehicleColor,
                                                           'YearofMake' => $YearofMake,
                                                           'VehicleMake' => $VehicleMake, 
                                                           'RegistrationNo' => $RegistrationNo, 
                                                           'VehicleType' => $VehicleType,
                                                           'EngineCapacity' => $EngineCapacity,
                                                           'VehicleModel' => $VehicleModel,
                                                           'SumAssured' => $SumAssured,
                                                           'Premium' => $Premium,
                                                           'CoverNoteNo' => $CoverNoteNo,
                                                           'CertificateNo' => $CertificateNo,
                                                           'GeographicalZone' => $GeographicalZone
                                                    );

$s = new nusoap_client($wsdlfile, 'wsdl');
//$s = new nusoap_client($wsdlfile);
// if (empty($proxyhost))
// {
// }else
// {
//         $s->setHTTPProxy($proxyhost,$proxyport,$proxyusr,$proxypassword);
// }



$result = $s->call('Vehicle_Policy_Push', $params, '', '', false, true);
if($result){
print_r($result);
echo '<META HTTP-EQUIV="Refresh" Content="3; URL=records.php">';





}else{
    echo '<META HTTP-EQUIV="Refresh" Content="3; URL=error.php">';

}






?>

我的警报代码

代码语言:javascript
复制
<?php
$reply = $_POST['Email'];



    $replysubject = "Auto-Reply: support | kblinsurance.com";
    $replyfrom = "From: noreply@kblinsurance.com\r\n";
     $replymessagess .= "You Are Getting This Email.\r\n\r\n";
      $replymessagess .= "Because You Just Purchased A Third Party Insurance.\r\n\r\n";


     $replymessagess .= $_POST["Insured_Name"];
    $replymessagess .= "\r\n";

      $replymessagess .= "\r\n";
     $replymessagess .= "Telephone Number :\r\n";
    $replymessagess .= $_POST["Telephone"];
    $replymessagess .= "\r\n";
     $replymessagess .= "\r\n";
    $replymessagess .= "With Registeration Number :\r\n";
    $replymessagess .= $_POST["Registeration_Number"];
    $replymessagess .= "\r\n\r\n";

    $replymessagess .= "http://www.kblinsurance.com\r\n\r\n";
    $replymessagess .= "This e-mail is automated, so please do not reply.\r\n";
     $replymessagess .= "Regards.\r\n";
    mail($reply,$replysubject, $replymessagess, $replyfrom);
    ?>

我只想在我的webservice帖子成功的时候发送警报,有什么建议吗?

EN

回答 2

Stack Overflow用户

发布于 2015-03-17 20:08:09

代码语言:javascript
复制
if (mail($reply,$replysubject, $replymessagess, $replyfrom)) {
    // Your alert here: e.g:
    echo "Successfully sent";
} 

这基本上意味着,如果mail函数返回true,则执行警报。您还可以检查它是否成功:

代码语言:javascript
复制
if (!mail($reply,$replysubject, $replymessagess, $replyfrom)) {
    // Was not successful
    echo "Not successfully sent";
} // Note the !

或者对于成功和不成功:

代码语言:javascript
复制
if (mail($reply,$replysubject, $replymessagess, $replyfrom)) {
    // Your alert here
    echo "Successfully sent";
} else {
    // Your unsucessful alert
    echo "Not successfully sent";
}

http://php.net/manual/en/function.mail.php返回值?

如果邮件已成功接受传递,则返回TRUE;否则返回FALSE。

票数 1
EN

Stack Overflow用户

发布于 2015-03-17 20:16:52

试试这个:

代码语言:javascript
复制
$result = $s->call('Vehicle_Policy_Push', $params, '', '', false, true);

if($result){

    $reply = $_POST['Email'];

    $replysubject = "Auto-Reply: support | kblinsurance.com";
    $replyfrom = "From: noreply@kblinsurance.com\r\n";
    $replymessagess .= "You Are Getting This Email.\r\n\r\n";
    $replymessagess .= "Because You Just Purchased A Third Party                   Insurance.\r\n\r\n";


    $replymessagess .= $_POST["Insured_Name"];
    $replymessagess .= "\r\n";

    $replymessagess .= "\r\n";
    $replymessagess .= "Telephone Number :\r\n";
    $replymessagess .= $_POST["Telephone"];
    $replymessagess .= "\r\n";
    $replymessagess .= "\r\n";
    $replymessagess .= "With Registeration Number :\r\n";
    $replymessagess .= $_POST["Registeration_Number"];
    $replymessagess .= "\r\n\r\n";

    $replymessagess .= "http://www.kblinsurance.com\r\n\r\n";
    $replymessagess .= "This e-mail is automated, so please do not reply.\r\n";
    $replymessagess .= "Regards.\r\n";
    mail($reply,$replysubject, $replymessagess, $replyfrom);
}

仅仅是猜测就需要更多的信息。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29098614

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档