My goal is to have the user fill out a form with country and postal code, post the data to a php script that makes a call to fedex's server and returns shipment rates.
I have successfully accomplished this on my local web server, but upon implementation to my WordPress site, the php script does not execute when the form data is posted. My code is as follows:
rate.php (form and php script both in this file):
<!-- FORM -->
<h1 style="font-family: "Ek Mukta", sans-serif;">Quick Quote</h1>
<br>
<form id="quick-quote" class="" action="" method="post">
<label>Country</label>
<br>
<input id="country" type="text" name="country" value="">
<br>
<label>Postal Code</label>
<br>
<input id="postal" type="text" name="postal" value="">
<br>
<br>
<input id="submit" type="submit" name="" value="submit">
</form>
<br>
<!-- FEDEX CALL -->
<?php
print_r($_POST); //this works!
error_reporting(E_ALL);
session_start();
require_once('../../library/fedex-common.php'); //code seems to break here
$newline = "<br />";
//The WSDL is not included with the sample code.
//Please include and reference in $path_to_wsdl variable.
$path_to_wsdl = "RateService/RateService_v20.wsdl";
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient($path_to_wsdl, array('trace' => 1)); // Refer to http://us3.php.net/manual/en/ref.soap.php for more information
$request['WebAuthenticationDetail'] = array(
'UserCredential' =>array(
'Key' => getProperty('key'),
'Password' => getProperty('password')
)
);
$request['ClientDetail'] = array(
'AccountNumber' => getProperty('shipaccount'),
'MeterNumber' => getProperty('meter')
);
$request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Request v20 using PHP ***');
$request['Version'] = array(
'ServiceId' => 'crs',
'Major' => '20',
'Intermediate' => '0',
'Minor' => '0'
);
$request['ReturnTransitAndCommit'] = true;
$request['RequestedShipment']['DropoffType'] = 'REGULAR_PICKUP'; // valid values REGULAR_PICKUP, REQUEST_COURIER, ...
$request['RequestedShipment']['ShipTimestamp'] = date('c');
$request['RequestedShipment']['ServiceType'] = 'INTERNATIONAL_ECONOMY'; // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
$request['RequestedShipment']['PackagingType'] = 'YOUR_PACKAGING'; // valid values FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
$request['RequestedShipment']['TotalInsuredValue']=array('Ammount'=>0,'Currency'=>'USD');
$request['RequestedShipment']['Shipper'] = addShipper();
$request['RequestedShipment']['Recipient'] = addRecipient();
$request['RequestedShipment']['VariableHandlingChargeDetail'] = addHandlingCharge();
$request['RequestedShipment']['ShippingChargesPayment'] = addShippingChargesPayment();
//$request['RequestedShipment']['RateRequestTypes'] = addRateType();
$request['RequestedShipment']['RateRequestTypes'] = 'LIST';
// $request['RequestedShipment']['RateRequestTypes'] = 'PREFERRED ';
$request['RequestedShipment']['PackageCount'] = '1';
$request['RequestedShipment']['RequestedPackageLineItems'] = addPackageLineItem1();
try
{
if(setEndpoint('changeEndpoint'))
{
$newLocation = $client->__setLocation(setEndpoint('endpoint'));
}
$response = $client ->getRates($request);
if ($response -> HighestSeverity != 'FAILURE' && $response -> HighestSeverity != 'ERROR')
{
$rateReply = $response -> RateReplyDetails;
echo '<table>';
$country = $_POST['country'];
$postal = $_POST['postal'];
$productPrice = 100;
$serviceFee = 50;
echo $country;
// echo '<tr><td>Country Code </td><td>Postal Code</td><td>Service Type</td><td>Amount</td><td>Delivery Date</td></tr><tr>';
$serviceType = '<td>'.$rateReply -> ServiceType . '</td>';
$amount = number_format($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalVariableHandlingCharges->TotalCustomerCharge->Amount,2,".",",");
if(array_key_exists('DeliveryTimestamp',$rateReply)){
$deliveryDate= '<td>' . $rateReply->DeliveryTimestamp . '</td>';
}else if(array_key_exists('TransitTime',$rateReply)){
$deliveryDate= '<td>' . $rateReply->TransitTime . '</td>';
}else {
$deliveryDate='<td> </td>';
}
$total = $productPrice + $serviceFee + $amount;
// echo "<td>$country</td>. <td>$postal</td>. $serviceType. <td>$amount</td>. $deliveryDate";
// echo '</tr>';
// echo '</table>';
echo
"
<h3>Country Code: $country</h3>
<h3>Postal Code: $postal</h3>
<br>
<table>
<tr>
<td>Product Cost</td>
<td>Shipping Cost</td>
<td>Service Fee</td>
<td>Total</td>
</tr>
<br>
<tr>
<td>$$productPrice<span>+</span></td>
<td>$$amount<span>+</span></td>
<td>$$serviceFee<span>=</span></td>
<td>$$total </td>
</tr>
</table>";
printSuccess($client, $response);
}
else
{
printError($client, $response);
}
writeToLog($client); // Write to log file
} catch (SoapFault $exception) {
printFault($exception, $client);
}
//FUNCTIONS
function addShipper(){
$shipper = array(
'Contact' => array(
'PersonName' => 'XXX',
'CompanyName' => 'XXX',
'PhoneNumber' => 'XXX'),
'Address' => array(
'StreetLines' => array('Address Line 1'),
'City' => 'New York',
'StateOrProvinceCode' => 'XXX',
'PostalCode' => 'XXXX',
'CountryCode' => 'US')
);
return $shipper;
}
function addRecipient(){
$country = $_POST['country'];
$postal = $_POST['postal'];
$recipient = array(
'Contact' => array(
'PersonName' => 'Recipient Name',
'CompanyName' => 'Company Name',
'PhoneNumber' => 'XXX'
),
'Address' => array(
'StreetLines' => array('Address Line 1'),
'City' => '',
'StateOrProvinceCode' => '',
'PostalCode' => ''.$postal.'',
'CountryCode' => ''.$country.'',
'Residential' => false)
);
return $recipient;
}
//HANDLING CHARGE
function addHandlingCharge(){
$VariableHandlingChargeDetail = array(
'RateTypeBasis' => 'LIST',
'RateElementBasis' => 'BASE_CHARGE', // valid values NET_CHARGE, NET_CHARGE_EXCLUDING_TAXES, NET_FREIGHT
'FixedValue' => array('Currency' => 'USD', 'Amount' => 0),
'PercentValue' => '0',
);
return $VariableHandlingChargeDetail;
};
function addShippingChargesPayment(){
$shippingChargesPayment = array(
'PaymentType' => 'SENDER', // valid values RECIPIENT, SENDER and THIRD_PARTY
'Payor' => array(
'ResponsibleParty' => array(
'AccountNumber' => getProperty('billaccount'),
// 'PostalCode' => '10036',
'CountryCode' => 'US')
)
);
return $shippingChargesPayment;
}
function addLabelSpecification(){
$labelSpecification = array(
'LabelFormatType' => 'COMMON2D', // valid values COMMON2D, LABEL_DATA_ONLY
'ImageType' => 'PDF', // valid values DPL, EPL2, PDF, ZPLII and PNG
'LabelStockType' => 'PAPER_7X4.75');
return $labelSpecification;
}
function addSpecialServices(){
$specialServices = array(
'SpecialServiceTypes' => array('COD'),
'CodDetail' => array(
'CodCollectionAmount' => array('Currency' => 'USD', 'Amount' => 150),
'CollectionType' => 'ANY')// ANY, GUARANTEED_FUNDS
);
return $specialServices;
}
function addPackageLineItem1(){
$packageLineItem = array(
'SequenceNumber'=>1,
'GroupPackageCount'=>1,
'Weight' => array(
'Value' => 2,
'Units' => 'LB'
),
'Dimensions' => array(
'Length' => 2,
'Width' => 2,
'Height' => 2,
'Units' => 'IN'
)
);
return $packageLineItem;
}
?>
quick-quote.php (template file to include feature on specific pages):
<?php /* Template Name: quick-quote */ ?>
<?php
get_header();
include('RateService_v20_php/RateAvailableServicesService_v20_php/php/RateWebServiceClient/RateAvailableServices/RateAvailableServicesWebServiceClient.php');
get_footer();
?>
functions.php (relevant code only):
add_action( 'admin_post_quick_quote', 'prefix_admin_quick_quote' );
function prefix_admin_quick_quote() {
// What do I do here!?
}
The issue that I have having is this:
-I fill out the form
-hit submit
-print_r($_POST) the data to see if form posted correctly (it does)
-any code after require_once('../../library/fedex-common.php'); does not execute
Things I have already checked/tried:
-PHP and SOAP are installed correctly on the server
-all files are excessible 664 not 666
-ran the file on the server, it works fine
-setting the form's action to "rate.php" or "quick-quote.php" (form posts data to same page so I think this can be left blank)
-made sure ('../../library/fedex-common.php') is the correct path
So my questions are:
-How do I make the php script execute after the form is submitted?
-Is this accomplished using functions.php to hook into admin-post.php?
Thanks so much!
It sounds like PHP does not have access to fedex-common.php.
Change the relative path for the 'require_once` to an absolute path.
Check that the application has permissions to the directory.
Check that the application has permissions to execute the file.
Additionally, you can check that the include is success by replacing the 'require_once' with the following to further determine if the issue actually a side effect of the file location or an issue with the referenced file.
if(!#include_once("/PATH/TO/library/fedex-common.php")) {
throw new Exception ('fedex-common.php does not exist');
}
Related
require_once('modules/FedEx/RateAvailableServicesService_v18_php/library/fedex-common.php5');
$path_to_wsdl = PATH."modules/FedEx/RateAvailableServicesService_v18_php/RateService_v18.wsdl";
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient($path_to_wsdl, array('trace' => 1)); // Refer to http://us3.php.net/manual/en/ref.soap.php for more information
$request['WebAuthenticationDetail'] = array(
//'ParentCredential' => array(
//'Key' => $this->getProperty('key'),
//'Password' => $this->getProperty('password')
//),
'UserCredential' => array(
'Key' => $this->getProperty('key'),
'Password' => $this->getProperty('password')
)
);
$request['ClientDetail'] = array(
'AccountNumber' => $this->getProperty('shipaccount'),
'MeterNumber' => $this->getProperty('meter')
);
$request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Available Services Request using PHP ***');
$request['Version'] = array(
'ServiceId' => 'crs',
'Major' => '18',
'Intermediate' => '0',
'Minor' => '1'
);
$request['ReturnTransitAndCommit'] = true;
$request['RequestedShipment']['DropoffType'] = 'REGULAR_PICKUP'; // valid values REGULAR_PICKUP, REQUEST_COURIER, ...
$request['RequestedShipment']['ShipTimestamp'] = date('c');
// Service Type and Packaging Type are not passed in the request
$request['RequestedShipment']['ServiceType'] = 'INTERNATIONAL_PRIORITY'; // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
$request['RequestedShipment']['Shipper'] = array(
'Address'=> array('StreetLines' => array($UL->str_add1,$UL->str_add2),'City' => $UL->city_name,'StateOrProvinceCode' => $UL->state_name,'PostalCode' => $UL->zipcode,'CountryCode' => $UL->country_code));
$request['RequestedShipment']['Recipient'] = array(
'Address'=>array('StreetLines' => array($this->session->get('shipping_address1'),$this->session->get('shipping_address2')),'City' => $shipping_city,'StateOrProvinceCode' => $shipping_state,'PostalCode' => $this->session->get('shipping_postal_code'),'CountryCode' => $country_code,'Residential' => false));
$request['RequestedShipment']['ShippingChargesPayment'] = array(
'PaymentType' => 'SENDER',
'Payor' => array(
'ResponsibleParty' => array(
'AccountNumber' => $this->getProperty('billaccount'),
'Contact' => null,
'Address' => array(
'CountryCode' => COUNTRY_CODE
)
)
)
);
$request['RequestedShipment']['PackageCount'] = '1';
$request['RequestedShipment']['RequestedPackageLineItems'] = array(
'0' => array(
'SequenceNumber' => 1,
'GroupPackageCount' => 1,
'Weight' => array(
'Value' => $UL->weight//,
//'Units' => 'LB'
),
'Dimensions' => array(
'Length' => $UL->length,
'Width' => $UL->width,
'Height' => $UL->height//,
//'Units' => 'IN'
)
)
);
try {
if(setEndpoint('changeEndpoint')){
$newLocation = $client->__setLocation(setEndpoint('endpoint'));
}
$response = $client ->getRates($request);
if ($response -> HighestSeverity != 'FAILURE' && $response -> HighestSeverity != 'ERROR'){
echo 'Rates for following service type(s) were returned.'. Newline. Newline;
echo '<table border="1">';
echo '<tr><td>Service Type</td><td>Amount</td><td>Delivery Date</td>';
if(is_array($response -> RateReplyDetails)){
foreach ($response -> RateReplyDetails as $rateReply){
$this->printRateReplyDetails($rateReply);
}
}else{
$this->printRateReplyDetails($response -> RateReplyDetails);
}
echo '</table>'. Newline;
printSuccess($client, $response);
}else{
printError($client, $response);
}
writeToLog($client); // Write to log file
} catch (SoapFault $exception) {
printFault($exception, $client);
}
Here is error exception which i am getting
Fault
Code:SOAP-ENV:Server
String:Fault
Request
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://fedex.com/ws/rate/v18"><SOAP-ENV:Body><ns1:RateRequest><ns1:WebAuthenticationDetail><ns1:UserCredential><ns1:Key>AndJurrJfCvvWZWn</ns1:Key><ns1:Password>Rps8Pl4jF9zGp5wiEpDRhKiHo</ns1:Password></ns1:UserCredential></ns1:WebAuthenticationDetail><ns1:ClientDetail><ns1:AccountNumber>631140688</ns1:AccountNumber><ns1:MeterNumber>107714405</ns1:MeterNumber></ns1:ClientDetail><ns1:TransactionDetail><ns1:CustomerTransactionId> *** Rate Available Services Request using PHP ***</ns1:CustomerTransactionId></ns1:TransactionDetail><ns1:Version><ns1:ServiceId>crs</ns1:ServiceId><ns1:Major>18</ns1:Major><ns1:Intermediate>0</ns1:Intermediate><ns1:Minor>1</ns1:Minor></ns1:Version><ns1:ReturnTransitAndCommit>true</ns1:ReturnTransitAndCommit><ns1:RequestedShipment><ns1:ShipTimestamp>2016-03-30T18:35:41+05:30</ns1:ShipTimestamp><ns1:DropoffType>REGULAR_PICKUP</ns1:DropoffType><ns1:ServiceType>INTERNATIONAL_PRIORITY</ns1:ServiceType><ns1:Shipper><ns1:Address><ns1:StreetLines>SUITE 5A-1204</ns1:StreetLines><ns1:StreetLines>799 E DRAGRAM</ns1:StreetLines><ns1:City>TUCSON</ns1:City><ns1:StateOrProvinceCode>AZ</ns1:StateOrProvinceCode><ns1:PostalCode>94040</ns1:PostalCode><ns1:CountryCode>US</ns1:CountryCode></ns1:Address></ns1:Shipper><ns1:Recipient><ns1:Address><ns1:StreetLines>795 E</ns1:StreetLines><ns1:StreetLines>DRAGRAM</ns1:StreetLines><ns1:City>TUCSON</ns1:City><ns1:StateOrProvinceCode>AZ</ns1:StateOrProvinceCode><ns1:PostalCode>94040</ns1:PostalCode><ns1:CountryCode>US</ns1:CountryCode><ns1:Residential>false</ns1:Residential></ns1:Address></ns1:Recipient><ns1:ShippingChargesPayment><ns1:PaymentType>SENDER</ns1:PaymentType><ns1:Payor><ns1:ResponsibleParty><ns1:AccountNumber>631140688</ns1:AccountNumber><ns1:Address><ns1:CountryCode>KWI</ns1:CountryCode></ns1:Address></ns1:ResponsibleParty></ns1:Payor></ns1:ShippingChargesPayment><ns1:PackageCount>1</ns1:PackageCount><ns1:RequestedPackageLineItems><ns1:SequenceNumber>1</ns1:SequenceNumber>
<ns1:GroupPackageCount>1</ns1:GroupPackageCount><ns1:Weight>
<ns1:Value>20</ns1:Value></ns1:Weight><ns1:Dimensions>
<ns1:Length>8</ns1:Length><ns1:Width>10</ns1:Width>
<ns1:Height>10</ns1:Height></ns1:Dimensions></ns1:RequestedPackageLineItems>
</ns1:RequestedShipment></ns1:RateRequest></SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Since you have trace on, you should look at the actual request/response data. When I took your raw POST data above (in which you shouldn't have posted your account/key info) I get back a schema validation error. Syntax looks correct but the country code for payor is KWI but should be US. I'd suggest you add some code to log the request and responses...
$soap_response_hdr = $client->__getLastResponseHeaders() ;
$soap_response = $client->__getLastResponse() ;
$soap_request_hdr = $client->__getLastRequestHeaders() ;
$soap_request = $client->__getLastRequest() ;
I am working on a campaign monitor api which creates a custom list with custom fields.
When I try and add subscribers it used to work, now when I look at the list its not added them. Although its still returning a success code 201.
function addSubscriber($list_id, $emailAddress, $name, $title, $showName, $showDate, $showTime){
//create subscriber
$subscriber = array(
'EmailAddress' => $emailAddress,
'Name' => $name,
'CustomFields' => array(
array(
'Key' => "Title",
'Value' => $title
),
array(
'Key' => "ShowName",
'Value' => $showName
),
array(
'Key' => "ShowDate",
'Value' => $showDate
),
array(
'Key' => "ShowTime",
'Value' => $showTime
)
),
'Resubscribe' => true,
'RestartSubscriptionBasedAutoResponders' => true
);
//print_r($subscriber);
$subwrap = new CS_REST_Subscribers($list_id, $this->auth);
$result = $subwrap->add($subscriber);
//var_dump($result->response);
echo "Result of POST /api/v3.1/subscribers/{list id}.{format}\n<br />";
if($result->was_successful()) {
echo "Subscribed with code ".$result->http_status_code;
} else {
echo 'Failed with code '.$result->http_status_code."\n<br /><pre>";
var_dump($result->response);
echo '</pre>';
}
return $result->response;
}
This code is working for me.You need to add campaign monitor class files in you project folder and use valid list id and api key.You can find you api key from manage account link and list id from click on (change name/type) below list title. Please wait some time to see in you list.
require_once 'csrest_subscribers.php';
$name=$_POST['name'];
$email=$_POST['email'];
$wrap = new CS_REST_Subscribers('Your list ID', 'Your API Key');
$result = $wrap->add(array(
'EmailAddress' => $email,
'Name' => $name,
'CustomFields' => array(), // no custom fields, can remove this line completely
'Resubscribe' => true
));
echo "Result of POST /api/v3/subscribers/{list id}.{format}\n<br />";
if($result->was_successful()) {
echo "Subscribed with code ".$result->http_status_code;
} else {
echo 'Failed with code '.$result->http_status_code."\n<br /><pre>";
var_dump($result->response);
echo '</pre>';
}
I have used the PHPReport library content with the PHPExcel Library content. I am creating the website locally on my macbook using Xampp. The following code I wrote to fetch the data and generate the excel sheet:
public function fetchReportData($newStartDate, $newEndDate){
if ($this->getDBConnection()) {
$q = "select * from PMA where request_date between '".$newStartDate."' and '".$newEndDate ."'";
$r = mysqli_query($this->dbc, $q);
if ($r) {
$row_count = $r->num_rows;
if ($row_count == 0) {
echo '<div align="left">'
. '<b><font color="red">* </font>No requests were found in this period</b></div>';
} else {
$data = array();
while ($row = mysqli_fetch_array($r)) {
$desc = $this->returnDesc($row[0]);
$requestId = $this->getNormalReqID($row[0]);
$this->get($requestId);
$username = $this->getUserName($this->requestor_id);
$srv_id = $this->getSRVId($row[0]);
$this->getSRV($srv_id);
$srv_date = date("d-m-Y", strtotime($this->srv_date));
$srv = 'SRV dtd '.$srv_date;
if($this->srv_remarks == null)
{
$remark = $srv;
}
else
{
$remark = $this->srv_remarks;
}
$data[] =
array("Date" => $row[2], "Originator" => $username, "Material No" => $this->material_number,
"Description" => $desc, "Quantity" => $row[5], "Order Number" => $this->pm_order_number,
"Request Number" => $row[7], "Gate Pass No"=> $row[10], "Gate Pass Date"=> $row[14],
"SRV/Date" => $srv, "Received Qty" => $row[11], "Remarks" => $remark)
;
}
include_once 'PHPReport.php';
$R=new PHPReport();
$R->load(array(
'id'=>'product',
'header'=>array(
'Date'=>'Date', 'Originator' => 'Originator', 'Material No' => 'Material No',
'Description' => 'Description' , 'Quantity' => 'Quantity', 'Order Number' => 'Order Number',
'Request Number' => 'Request Number', 'Gate Pass No' => 'Gate Pass No', 'Gate Pass Date'=> 'Gate Pass Date',
'SRV/Date' => 'SRV/Date' , 'Received Qty' => 'Received Qty', 'Remarks' => 'Remarks'
),
'footer'=>array(
'Date'=>'', 'Originator' => '', 'Material No' => '',
'Description' => '' , 'Quantity' => '', 'Order Number' => '',
'Request Number' => '', 'Gate Pass No' => '', 'Gate Pass Date'=> '',
'SRV/Date' => '' , 'Received Qty' => '', 'Remarks' => ''
),
'data'=> $data
)
);
echo $R->render('excel');
}
}
}
}
It does not show any error while calling the code and it generates the xlsx sheet fine but I cannot open the file. I get the following error when I try to open the sheet:
The format or file extension is not valid. verify that the file has not been corrupted and the file extension matches the format of the file.
I get the same error while trying to open a PDF created by the library PHP to PDF, is it something wrong with my macbook?
I'm using a wamp server, and I've used this php script before when sending form values to an email..and it worked perfect before! I can't find what I've done with the code, or it might be something spooking with my wamp server, because it's not sending anymore and I get the error message: There was a problem sending your message.
Code:
// Create the form
$contactForm = new JFormer('contactForm', array(
'submitButtonText' => 'Send Message',
));
// Add components to the form
$contactForm->addJFormComponentArray(array(
new JFormComponentSingleLineText('artistname', 'Artist Name:', array(
'validationOptions' => array('required'),
'tip' => '<p>Enter your artist name.</p>'
)),
new JFormComponentSingleLineText('trackname', 'Track Name:', array(
'tip' => '<p>Enter your track name.</p>',
'validationOptions' => array('required'),
)),
new JFormComponentSingleLineText('email', 'E-mail Address:', array(
'tip' => '<p>Enter your email address.</p>',
'validationOptions' => array('required'),
)),
new JFormComponentSingleLineText('stream', 'Link to Stream:</br>(if applicable)', array(
'tip' => '<p>Enter your link to stream.</p>'
)),
new JFormComponentSingleLineText('download', 'Download Link:', array(
'tip' => '<p>Enter your download link.</p>',
'validationOptions' => array('required'),
)),
new JFormComponentMultipleChoice('multipleChoiceType', 'Full Track or Clip:',
array(
array('label' => 'Full Track', 'value' => 'fulltrack'),
array('label' => 'Clip', 'value' => 'clip'),
),
array(
'multipleChoiceType' => 'radio',
)),
new JFormComponentSingleLineText('downloadorpurchase', 'Free Download or
Purchase Link</br>(To be included in video description)', array(
'tip' => '<p>Enter your link.</p>',
)),
new JFormComponentSingleLineText('releasedate', 'Release Date:</br>(if applicable)', array(
'tip' => '<p>Enter the release date.</p>',
)),
new JFormComponentTextArea('artistandlabel', 'Artist / Label Links:</br>(To be included in description.)', array(
'validationOptions' => array('required'),
'tip' => '<p>Enter your description.</p>',
)),
new JFormComponentMultipleChoice('iagree', 'I confirm that I own full
copyright rights and grant the THU Records to post my music in their videos. I
understand that content may be monetized with adverts.',
array(
array('label' => 'I Accept', 'value' => 'accepted'),
array('label' => 'I Do Not Accept', 'value' => 'dontaccepted'),
),
array(
'iagree' => 'radio',
'validationOptions' => array('required'),
)),
));
// Set the function for a successful form submission
function onSubmit($formValues) {
// Concatenate the name
if(!empty($formValues->name->middleInitial)) {
$name = $formValues->name->firstName . ' ' . $formValues->name->middleInitial . ' ' . $formValues->name->lastName;
}
else {
$name = $formValues->name->firstName . ' ' . $formValues->name->lastName;
}
// Prepare the variables for sending the mail
$to = 'lill_z4ck3#hotmail.com';
$fromAddress = $formValues->email;
$trackName = $formValues->trackname;
$streamLink = $formValues->stream;
$download = $formValues->download;
$trackorclip = $formValues->multipleChoiceType;
$downloadOrPurchase = $formValues->downloadorpurchase;
$releaseDate = $formValues->releasedate;
$artistAndLabel = $formValues->artistandlabel;
$agreement = $formValues->iagree;
$artistName = $formValues->artistname;
$subject = "Submit from ".$formValues->artistname;
$message = "Artist Name : ".$artistName."\nTrack Name : ".$trackName."\n
Email : ".$fromAddress."\n Stream Link : ".$streamLink."\nDownload link
: ".$download."\nTrack or Clip : ".$trackorclip."\nDownload or Purchase
: ".$downloadOrPurchase."\n Release Date : ".$releaseDate."\n Artist
and Label Info : ".$artistAndLabel."\n Agreement : ".$agreement;
// Use the PHP mail function
$mail = mail($to, $subject, $message);
// Send the message
if($mail) {
$response['successPageHtml'] = '
<h1>Thanks for Contacting Us</h1>
<p>Your message has been successfully sent.</p>
';
}
else {
$response['failureNoticeHtml'] = '
There was a problem sending your message.
';
}
return $response;
}
// Process any request to the form
$contactForm->processRequest();
Do anyone of you have any idea what could be wrong? :(
The mail() function usually doesn't work by default for things like WAMP. You will need to add details of your SMTP server to the php.ini file and then configure some other settings.
This is a nice tutorial: http://roshanbh.com.np/2007/12/sending-e-mail-from-localhost-in-php-in-windows-environment.html
Hope this helps.
THE SOAP REQUEST AS SENT
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://fedex.com/ws/ship/v12">
<SOAP-ENV:Body>
<ns1:ProcessShipmentRequest>
<ns1:WebAuthenticationDetail>
<ns1:UserCredential>
<ns1:Key>kQyj3MtQGLJ3ZYWG</ns1:Key>
<ns1:Password>66ywMwyasljK5uRkaNENRZCZW</ns1:Password>
</ns1:UserCredential>
</ns1:WebAuthenticationDetail>
<ns1:ClientDetail>
<ns1:AccountNumber>510087682</ns1:AccountNumber>
<ns1:MeterNumber>100154483</ns1:MeterNumber>
</ns1:ClientDetail>
<ns1:TransactionDetail>
<ns1:CustomerTransactionId>*** Express Domestic Shipping Request v12 using PHP ***</ns1:CustomerTransactionId>
</ns1:TransactionDetail>
<ns1:Version>
<ns1:ServiceId>ship</ns1:ServiceId>
<ns1:Major>12</ns1:Major>
<ns1:Intermediate>1</ns1:Intermediate>
<ns1:Minor>0</ns1:Minor>
</ns1:Version>
<ns1:RequestedShipment>
<ns1:ShipTimestamp>2013-03-25T14:33:08+00:00</ns1:ShipTimestamp>
<ns1:DropoffType>REGULAR_PICKUP</ns1:DropoffType>
<ns1:ServiceType>FEDEX_GROUND</ns1:ServiceType>
<ns1:PackagingType>YOUR_PACKAGING</ns1:PackagingType>
<ns1:TotalWeight>
<ns1:Units>LB</ns1:Units>
<ns1:Value>17.22</ns1:Value>
</ns1:TotalWeight>
<ns1:Shipper>
<ns1:Contact>
<ns1:PersonName>Shipping Department</ns1:PersonName>
<ns1:CompanyName>Big Dog Treestands</ns1:CompanyName>
<ns1:PhoneNumber>3092636800</ns1:PhoneNumber>
</ns1:Contact>
<ns1:Address>
<ns1:StreetLines>120 E. Detroit Parkway</ns1:StreetLines>
<ns1:City>Morton</ns1:City>
<ns1:StateOrProvinceCode>IL</ns1:StateOrProvinceCode>
<ns1:PostalCode>61550</ns1:PostalCode>
<ns1:CountryCode>US</ns1:CountryCode>
</ns1:Address>
</ns1:Shipper>
<ns1:Recipient>
<ns1:Contact>
<ns1:PersonName>David Sinc</ns1:PersonName>
<ns1:CompanyName>TEST COMPANY</ns1:CompanyName>
<ns1:PhoneNumber>3093701229</ns1:PhoneNumber>
</ns1:Contact>
<ns1:Address>
<ns1:StreetLines>1202 Chalet Ln</ns1:StreetLines>
<ns1:StreetLines>HIDDLY- Test Account</ns1:StreetLines>
<ns1:City>PEORIA</ns1:City>
<ns1:StateOrProvinceCode>IL</ns1:StateOrProvinceCode>
<ns1:PostalCode>61614</ns1:PostalCode>
<ns1:CountryCode>US</ns1:CountryCode>
<ns1:Residential>false</ns1:Residential>
</ns1:Address>
</ns1:Recipient>
<ns1:ShippingChargesPayment>
<ns1:PaymentType>SENDER</ns1:PaymentType>
<ns1:Payor>
<ns1:ResponsibleParty>
<ns1:AccountNumber>510087682</ns1:AccountNumber>
<ns1:Contact/>
<ns1:Address>
<ns1:CountryCode>US</ns1:CountryCode>
</ns1:Address>
</ns1:ResponsibleParty>
</ns1:Payor>
</ns1:ShippingChargesPayment>
<ns1:LabelSpecification>
<ns1:LabelFormatType>COMMON2D</ns1:LabelFormatType>
<ns1:ImageType>PDF</ns1:ImageType>
<ns1:LabelStockType>PAPER_8.5X11_TOP_HALF_LABEL</ns1:LabelStockType>
</ns1:LabelSpecification>
<ns1:RateRequestTypes>ACCOUNT</ns1:RateRequestTypes>
<ns1:PackageCount>1</ns1:PackageCount>
<ns1:RequestedPackageLineItems>
<ns1:SequenceNumber>1</ns1:SequenceNumber>
<ns1:GroupPackageCount>1</ns1:GroupPackageCount>
<ns1:Weight>
<ns1:Units>LB</ns1:Units>
<ns1:Value>17.22</ns1:Value>
</ns1:Weight>
</ns1:RequestedPackageLineItems>
</ns1:RequestedShipment>
</ns1:ProcessShipmentRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Fedex APpplication Code
<?php
// Copyright 2009, FedEx Corporation. All rights reserved.
// Version 12.0.0
require_once('library/fedex-common.php5');
//The WSDL is not included with the sample code.
//Please include and reference in $path_to_wsdl variable.
$path_to_wsdl = "http://bigdog.webdesign309.com/wp-content/themes/bigdogtreestands-new/woocommerce/emails/ShipWebServiceClient/wsdl/ShipService_v12.wsdl";
$uploads = wp_upload_dir();
define('SHIP_LABEL', $uploads['basedir'].'/shippinglabels/shipexpresslabel'.str_replace('#','',$order->get_order_number()).'.pdf'); // PNG label file. Change to file-extension .pdf for creating a PDF label (e.g. shiplabel.pdf)
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient($path_to_wsdl, array('trace' => 1)); // Refer to http://us3.php.net/manual/en/ref.soap.php for more information
$request['WebAuthenticationDetail'] = array(
'UserCredential' => array(
'Key' => getProperty('key'),
'Password' => getProperty('password')
)
);
$request['ClientDetail'] = array(
'AccountNumber' => getProperty('shipaccount'),
'MeterNumber' => getProperty('meter')
);
$request['TransactionDetail'] = array('CustomerTransactionId' => '*** Express Domestic Shipping Request v12 using PHP ***');
$request['Version'] = array(
'ServiceId' => 'ship',
'Major' => '12',
'Intermediate' => '1',
'Minor' => '0'
);
$ships = $order->get_shipping_method();
$shippingType = "FEDEX_GROUND";
if($ships == "Fedex Ground"){
$shippingType = "FEDEX_GROUND";
}
else if( $ships == "Fedex 2 Day"){
$shippingType = "FEDEX_2_DAY";
}
else if($ships == "Fedex Standard Overnight"){
$shippingType = "STANDARD_OVERNIGHT";
}
else if($ships == "Fedex Home Delivery"){
$shippingType = "GROUND_HOME_DELIVERY";
}
function totalOrderWeight($orders) {
$totalWeight = 0;
$items = $orders->get_items();
foreach($items as $item) {
$product = get_product( $item['product_id'] );
$quantity = intval( $item['qty'] );
$totalWeight += $product->get_weight() * $quantity;
}
return $totalWeight;
}
$request['RequestedShipment'] = array(
'ShipTimestamp' => date('c'),
'DropoffType' => 'REGULAR_PICKUP', // valid values REGULAR_PICKUP, REQUEST_COURIER, DROP_BOX, BUSINESS_SERVICE_CENTER and STATION
'ServiceType' => $shippingType, // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
'PackagingType' => 'YOUR_PACKAGING', // valid values FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
'TotalWeight' => array('Value' => totalOrderWeight($order), 'Units' => 'LB'), // valid values LB and KG
'Shipper' => addShipper(),
'Recipient' => addRecipient($order),
'ShippingChargesPayment' => addShippingChargesPayment(),
'LabelSpecification' => addLabelSpecification(),
'RateRequestTypes' => array('ACCOUNT'), // valid values ACCOUNT and LIST
'PackageCount' => 1,
'RequestedPackageLineItems' => array(
'0' => addPackageLineItem1(totalOrderWeight($order))
)
);
try
{
if(setEndpoint('changeEndpoint'))
{
$newLocation = $client->__setLocation(setEndpoint('endpoint'));
}
$response = $client->processShipment($request); // FedEx web service invocation
if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR')
{
printSuccess($client, $response);
$label =
// Create PNG or PDF label
// Set LabelSpecification.ImageType to 'PDF' or 'PNG for generating a PDF or a PNG label
$fp = fopen(SHIP_LABEL, 'wb');
fwrite($fp, $response->CompletedShipmentDetail->CompletedPackageDetails->Label->Parts->Image); //Create PNG or PDF file
fclose($fp);
// echo 'Click Here to Download Shipping Label was generated.';
}
else
{
printError($client, $response);
}
writeToLog($client); // Write to log file
} catch (SoapFault $exception) {
printFault($exception, $client);
}
function addShipper(){
$shipper = array(
'Contact' => array(
'PersonName' => 'Shipping Department',
'CompanyName' => 'Big Dog Treestands',
'PhoneNumber' => '3092636800'),
'Address' => array(
'StreetLines' => array('120 E. Detroit Parkway'),
'City' => 'Morton',
'StateOrProvinceCode' => 'IL',
'PostalCode' => '61550',
'CountryCode' => 'US')
);
return $shipper;
}
function addRecipient($orders){
$residential = get_post_meta($orders->get_order_number(), '_residential-indicator');
/* echo 'Shipping Address 2:'.$orders->shipping_address_2;
echo 'Shipping Address 1:'.$orders->shipping_address_1; */
if($orders->shipping_address_2){
$addressArray = array($orders->shipping_address_1, $orders->shipping_address_2);
/* echo 'Shipping Address 2'; */
/* $addressArray =array('StreetLines' => array('Address Line 1' => $orders->shipping_address_1, 'Address Line 2' => $orders->shipping_address_2)); */
}
else{
$addressArray = array($orders->shipping_address_1);
/* echo 'Shipping Address 1'; */
}
$joy = false;
if($residential == 1){
$joy = true;
}
else{
$joy = false;
}
$recipient = array(
'Contact' => array(
'PersonName' => $orders->billing_first_name . ' ' . $orders->billing_last_name,
'CompanyName' => $orders->shipping_company,
'PhoneNumber' => $orders->billing_phone),
/* 'Address' => array(
'StreetLines' => array($orders->shipping_address_1, $orders->shipping_address_2),
'City' => $orders->shipping_city,
'StateOrProvinceCode' => $orders->shipping_state,
'PostalCode' => $orders->shipping_postcode,
'CountryCode' => 'US',
'Residential' => $joy) */
'Address' => array(
'StreetLines'=>array($orders->shipping_address_1, $orders->shipping_address_2),
//array(utf8_encode($orders->shipping_address_1), utf8_encode($orders->shipping_address_2)),
'City' => $orders->shipping_city,
'StateOrProvinceCode' => $orders->shipping_state,
'PostalCode' => $orders->shipping_postcode,
'CountryCode' => 'US',
'Residential' => $joy)
);
return $recipient;
}
function addShippingChargesPayment(){
$shippingChargesPayment = array('PaymentType' => 'SENDER',
'Payor' => array(
'ResponsibleParty' => array(
'AccountNumber' => getProperty('billaccount'),
'Contact' => null,
'Address' => array('CountryCode' => 'US'))));
return $shippingChargesPayment;
}
function addLabelSpecification(){
$labelSpecification = array(
'LabelFormatType' => 'COMMON2D', // valid values COMMON2D, LABEL_DATA_ONLY
'ImageType' => 'PDF', // valid values DPL, EPL2, PDF, ZPLII and PNG
'LabelStockType' => 'PAPER_8.5X11_TOP_HALF_LABEL');
return $labelSpecification;
}
function addPackageLineItem1($weight){
$packageLineItem = array(
'SequenceNumber'=>1,
'GroupPackageCount'=>1,
'Weight' => array(
'Value' => $weight,
'Units' => 'LB')
);
return $packageLineItem;
}
?>
It returns this http://bigdog.webdesign309.com/assets/shippinglabels/shipexpresslabel1303.pdf
I have tried everything even calling fedex and they say that they provide no support for this issue as the code is a convenience rather than a service. If anyone can shed some light on this most puzzling issue as to why the second address field never shows up that would be great.
Any thoughts on this one?
In case anyone else comes across this problem, note that FedEx's test labels from their staging environment do not appear to ever include the second address line.
All of my test labels did NOT have a second address line, but as soon as I switched to the production server, the labels had the second line.
It should have multiple address lines as your XML looks valid. FedEx support should be able to provide assistance based on the SOAP request/response, but will not provide assistance with your PHP coding.
according to the Ship Service Docs, you only have two address lines, I solved like this:
'Address' => array(
'StreetLines' => array($array_recipient["address_1"],$array_recipient["address_2"]),
'City' => $array_recipient["City"],
'StateOrProvinceCode' => $array_recipient["StateOrProvinceCode"],
'PostalCode' => $array_recipient["PostalCode"],
'CountryCode' => 'MX',
'Residential' => true
)
in case you need more "space" you can use CUSTOMER_REFERENCE (rigth after dimensions):
$packageLineItem = array(
'SequenceNumber'=>1,
'GroupPackageCount'=>1,
'Weight' => array(
'Value' => $dimension_array["weight"],
'Units' => 'KG'
),
'Dimensions' => array(
'Length' => $dimension_array["length"],
'Width' => $dimension_array["width"],
'Height' => $dimension_array["height"],
'Units' => 'CM'
),
'CustomerReferences' => array(
'CustomerReferenceType' => 'CUSTOMER_REFERENCE',
'Value' => $dimension_array["more_references"]
),
If you make the request in Test Enviroment, the second address will not show, but after to production, the second address will shown.
Hope this help you.