I have been looking for a mailform script and came up with his. Works fine, but just this matter: when I reply to the received email, I am replying to myself, whilst I would like to reply automatically to the mailadres of the sender.
<?php
$to = "MY#MAILADRES.COM";
$subject = "mail via website";
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$onderwerp = $_POST['onderwerp'];
$comments = $_POST['message'];
$message = "
name: $firstname $lastname
email: $email
subject: $onderwerp
message: $comments
";
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
$headers = "From: MY#MAILADRES.COM\r\n".
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
foreach($_FILES as $userfile)
{
$tmp_name = $userfile['tmp_name'];
$type = $userfile['type'];
$name = $userfile['name'];
$size = $userfile['size'];
if (file_exists($tmp_name))
{
if(is_uploaded_file($tmp_name))
{
$file = fopen($tmp_name,'rb');
$data = fread($file,filesize($tmp_name));
fclose($file);
$data = chunk_split(base64_encode($data));
}
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n";
}
}
$message.="--{$mime_boundary}--\n";
if (mail($to, $subject, $message, $headers))
echo "Thanks for getting in touch.<br>Your message wil get my full attention.<br>I will get back to you soon.";
else
echo "Error in mail.<br>Please try again.";
?>
What should I change in this code, please?
I added these (seperately):
$headers .= "From: Contact Form (Domain.com) <no-reply#domain.com>\r\n";
$headers .= "Reply-To: ".$_REQUEST['email']."<". $_REQUEST['email'].">\r\n"
But none seem to work. I got this code to work with and all good, except for the reply-to.
I am using ajax to call a method from the server that returns a string data. However I get the following error.
PHP Notice 'yii\base\ErrorException' with message 'Trying to get
property of non-object'
probably this line $first_day=$row->tblStaff2->first_day_service; gives the error.
public function actionGet_loyalty() {
$model = \common\models\staffs\TblStaff::find()->joinWith('tblStaff2')->all();
$string = "<table class='table table-striped'><tr><th>Name</th><th>Number of Years</th></tr>";
foreach ($model as $row) {
$first_day=$row->tblStaff2->first_day_service;
$midname = ucwords($row->midname);
$name = ucwords($row->firstname) . " " . $midname[0] . ". " . ucwords($row->lastname);
$string.="<tr>"
. "<td>" . $name . "</td>"
. "<td>" . $first_day . "</td>"
. "</tr>";
}
$string.="</table>";
return $string;
}
TblStaff relation
public function getTblStaff2() {
return $this->hasOne(TblStaff2::className(), ['staff_id' => 'id']);
}
I have modified your code. Find it below
public function actionGet_loyalty() {
$model = \common\models\staffs\TblStaff::find()->all();
$string = "<table class='table table-striped'><tr><th>Name</th><th>Number of Years</th></tr>";
foreach ($model as $row) {
//What I added
foreach($row->tblStaff2 as $value){
$first_day = $value->first_day_service;
//Here is where it stopped
$midname = ucwords($row->midname);
$name = ucwords($row->firstname) . " " . $midname[0] . ". " . ucwords($row->lastname);
$string.="<tr>"
. "<td>" . $name . "</td>"
. "<td>" . $first_day . "</td>"
. "</tr>";
}
}
$string.="</table>";
return $string;
}
You can remove the comments i added to it when you get it working.
Below is the script I am using for processing credit cards. Right now, the payment goes to me based on $clientId and $clientSecret. I am needing the recipient to be variable based on a users paypal email. If I have the users PayPal email, how would I go about pulling the appropriate information to send the money to the user?
#!/usr/bin/php
<?php
# Sandbox
$host = 'https://api.sandbox.paypal.com';
$clientId = 'ATopphBpQ1BOCE3Bi5QLdXH8XjH_btoKoXXHsMNSUVe9cx_nbiB0fpglcwNE';
$clientSecret = 'EFvOWhDKf9-F9uEEHaA4LV_t373Zk-B0-h2vT6d-1BjaqsrPo_DWH74wTJ_M';
$token = '';
// function to read stdin
function read_stdin() {
$fr=fopen("php://stdin","r"); // open our file pointer to read from stdin
$input = fgets($fr,128); // read a maximum of 128 characters
$input = rtrim($input); // trim any trailing spaces.
fclose ($fr); // close the file handle
return $input; // return the text entered
}
function get_access_token($url, $postdata) {
global $clientId, $clientSecret;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_USERPWD, $clientId . ":" . $clientSecret);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
# curl_setopt($curl, CURLOPT_VERBOSE, TRUE);
$response = curl_exec( $curl );
if (empty($response)) {
// some kind of an error happened
die(curl_error($curl));
curl_close($curl); // close cURL handler
} else {
$info = curl_getinfo($curl);
echo "Time took: " . $info['total_time']*1000 . "ms<br>";
curl_close($curl); // close cURL handler
if($info['http_code'] != 200 && $info['http_code'] != 201 ) {
echo "Received error: " . $info['http_code']. "<br>";
echo "Raw response:".$response."<br>";
die();
}
}
// Convert the result from JSON format to a PHP array
$jsonResponse = json_decode( $response );
return $jsonResponse->access_token;
}
function make_post_call($url, $postdata) {
global $token;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer '.$token,
'Accept: application/json',
'Content-Type: application/json'
));
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
#curl_setopt($curl, CURLOPT_VERBOSE, TRUE);
$response = curl_exec( $curl );
if (empty($response)) {
// some kind of an error happened
die(curl_error($curl));
curl_close($curl); // close cURL handler
} else {
$info = curl_getinfo($curl);
echo "Time took: " . $info['total_time']*1000 . "ms<br>";
curl_close($curl); // close cURL handler
if($info['http_code'] != 200 && $info['http_code'] != 201 ) {
echo "Received error: " . $info['http_code']. "<br>";
echo "Raw response:".$response."<br>";
die();
}
}
// Convert the result from JSON format to a PHP array
$jsonResponse = json_decode($response, TRUE);
return $jsonResponse;
}
function make_get_call($url) {
global $token;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer '.$token,
'Accept: application/json',
'Content-Type: application/json'
));
#curl_setopt($curl, CURLOPT_VERBOSE, TRUE);
$response = curl_exec( $curl );
if (empty($response)) {
// some kind of an error happened
die(curl_error($curl));
curl_close($curl); // close cURL handler
} else {
$info = curl_getinfo($curl);
echo "Time took: " . $info['total_time']*1000 . "ms<br>";
curl_close($curl); // close cURL handler
if($info['http_code'] != 200 && $info['http_code'] != 201 ) {
echo "Received error: " . $info['http_code']. "<br>";
echo "Raw response:".$response."<br>";
die();
}
}
// Convert the result from JSON format to a PHP array
$jsonResponse = json_decode($response, TRUE);
return $jsonResponse;
}
echo "<br>";
echo "###########################################<br>";
echo "Obtaining OAuth2 Access Token.... <br>";
$url = $host.'/v1/oauth2/token';
$postArgs = 'grant_type=client_credentials';
$token = get_access_token($url,$postArgs);
echo "Got OAuth Token: ".$token;
echo "<br> <br>";
echo "###########################################<br>";
echo "Making a Credit Card Payment... <br>";
$url = $host.'/v1/payments/payment';
$payment = array(
'intent' => 'sale',
'payer' => array(
'payment_method' => 'credit_card',
'funding_instruments' => array ( array(
'credit_card' => array (
'number' => '5500005555555559',
'type' => 'mastercard',
'expire_month' => 12,
'expire_year' => 2018,
'cvv2' => 111,
'first_name' => 'Joe',
'last_name' => 'Shopper'
)
))
),
'transactions' => array (array(
'amount' => array(
'total' => '7.47',
'currency' => 'USD'
),
'description' => 'payment by a credit card using a test script'
))
);
echo "<b>Payer Variable Details:</b> :";
print_r($payment['payer']);
$json = json_encode($payment);
$json_resp = make_post_call($url, $json);
foreach ($json_resp['links'] as $link) {
if($link['rel'] == 'self'){
$payment_detail_url = $link['href'];
$payment_detail_method = $link['method'];
}
}
$related_resource_count = 0;
$related_resources = "";
foreach ($json_resp['transactions'] as $transaction) {
if($transaction['related_resources']) {
$related_resource_count = count($transaction['related_resources']);
foreach ($transaction['related_resources'] as $related_resource) {
if($related_resource['sale']){
$related_resources = $related_resources."sale ";
$sale = $related_resource['sale'];
foreach ($sale['links'] as $link) {
if($link['rel'] == 'self'){
$sale_detail_url = $link['href'];
$sale_detail_method = $link['method'];
}else if($link['rel'] == 'refund'){
$refund_url = $link['href'];
$refund_method = $link['method'];
}
}
} else if($related_resource['refund']){
$related_resources = $related_resources."refund";
}
}
}
}
echo "Payment Created successfully: " . $json_resp['id'] ." with state '". $json_resp['state']."'<br>";
echo "Payment related_resources:". $related_resource_count . "(". $related_resources.")";
echo "<br> <br>";
echo "###########################################<br>";
echo "Obtaining Payment Details... <br>";
$json_resp = make_get_call($payment_detail_url);
echo "Payment details obtained for: " . $json_resp['id'] ." with state '". $json_resp['state']. "'";
echo "<br> <br>";
echo "###########################################<br>";
echo "Obtaining Sale details...<br>";
$json_resp = make_get_call($sale_detail_url);
echo "Sale details obtained for: " . $json_resp['id'] ." with state '". $json_resp['state']."'";
echo "<br> <br>";
echo "###########################################<br>";
echo "Refunding a Sale... <br>";
$refund = array(
'amount' => array(
'total' => '7.47',
'currency' => 'USD'
)
);
$json = json_encode($refund);
$json_resp = make_post_call($refund_url, $json);
echo "Refund processed " . $json_resp['id'] ." with state '". $json_resp['state']."'";
echo "<br> <br>";
echo "###########################################<br>";
echo "Obtaining Sale details...<br>";
$json_resp = make_get_call($sale_detail_url);
echo "Sale details obtained for: " . $json_resp['id'] ." with state '". $json_resp['state']."'";
echo "<br> <br>";
echo "###########################################<br>";
echo "Obtaining Payment Details... <br>";
$json_resp = make_get_call($payment_detail_url);
$related_resource_count = 0;
$related_resources = "";
foreach ($json_resp['transactions'] as $transaction) {
if($transaction['related_resources']) {
$related_resource_count = count($transaction['related_resources']);
foreach ($transaction['related_resources'] as $related_resource) {
if($related_resource['sale']){
$related_resources = $related_resources."sale ";
} else if($related_resource['refund']){
$related_resources = $related_resources."refund";
}
}
}
}
echo "Payment details obtained for: " . $json_resp['id'] ." with state '". $json_resp['state']. "' <br>";
echo "Payment related_resources:". $related_resource_count . "(". $related_resources.")";
echo "<br> <br>";
echo "###########################################<br>";
echo "Saving a Credit Card in vault... <br>";
$url = $host.'/v1/vault/credit-card';
$creditcard = array(
'payer_id' => 'testuser#yahoo.com',
'number' => '4417119669820331',
'type' => 'visa',
'expire_month' => 11,
'expire_year' => 2018,
'first_name' => 'John',
'last_name' => 'Doe'
);
$json = json_encode($creditcard);
$json_resp = make_post_call($url, $json);
$credit_card_id = $json_resp['id'];
echo "Credit Card saved ".$credit_card_id." with state '".$json_resp['state']."'";
echo "<br> <br>";
echo "###########################################<br>";
echo "Making a Payment with saved credit card... <br>";
$url = $host.'/v1/payments/payment';
$payment = array(
'intent' => 'sale',
'payer' => array(
'payment_method' => 'credit_card',
'funding_instruments' => array ( array(
'credit_card_token' => array (
'credit_card_id' => $credit_card_id,
'payer_id' => 'testuser#yahoo.com'
)
))
),
'transactions' => array (array(
'amount' => array(
'total' => '7.47',
'currency' => 'USD'
),
'description' => 'payment using a saved card'
))
);
$json = json_encode($payment);
$json_resp = make_post_call($url, $json);
echo "Payment Created successfully: " . $json_resp['id'] ." with state '". $json_resp['state']."'<br>";
echo "<br> <br>";
echo "###########################################<br>";
echo "Obtaining all Payments (list) ... <br>";
$payment_list_url = $host.'/v1/payments/payment?start_id=PAY-1JJ14633E59990232KE6QU3I';
$json_resp = make_get_call($payment_list_url);
echo "Number of Payment resources returned: " . count($json_resp['payments']);
$counter = 0;
foreach ($json_resp['payments'] as $payment) {
echo "<br>" . $counter++ . ". " . $payment['id'];
}
echo "<br>Next Payment ID: ". $json_resp['next_id'];
echo "<br>Obtaining subset (2-4) of the Payments ... <br>";
$payment_list_url = $host.'/v1/payments/payment?start_index=1&count=3';
$json_resp = make_get_call($payment_list_url);
echo "Number of Payment resources returned: " . count($json_resp['payments']);
$counter = 0;
foreach ($json_resp['payments'] as $payment) {
echo "<br>" . $counter++ . ". " . $payment['id'];
}
echo "<br>Next Payment ID: ". $json_resp['next_id'];
echo "<br>Obtaining the next 10 starting from the previous next_id ... <br>";
$payment_list_url = $host.'/v1/payments/payment?start_id='.$json_resp['next_id'];
$json_resp = make_get_call($payment_list_url);
echo "Number of Payment resources returned: " . count($json_resp['payments']);
$counter = 0;
foreach ($json_resp['payments'] as $payment) {
echo "<br>" . $counter++ . ". " . $payment['id'];
}
echo "<br> <br>";
echo "###########################################<br>";
echo "Making a Credit Card Authorization... <br>";
$url = $host.'/v1/payments/payment';
$payment = array(
'intent' => 'authorize',
'payer' => array(
'payment_method' => 'credit_card',
'funding_instruments' => array ( array(
'credit_card' => array (
'number' => '5500005555555559',
'type' => 'mastercard',
'expire_month' => 12,
'expire_year' => 2018,
'cvv2' => 111,
'first_name' => 'Joe',
'last_name' => 'Shopper'
)
))
),
'transactions' => array (array(
'amount' => array(
'total' => '7.47',
'currency' => 'USD'
),
'description' => 'payment by a credit card using a test script'
))
);
$json = json_encode($payment);
$json_resp = make_post_call($url, $json);
foreach ($json_resp['links'] as $link) {
if($link['rel'] == 'self'){
$payment_detail_url = $link['href'];
$payment_detail_method = $link['method'];
}
}
$related_resource_count = 0;
$related_resources = "";
foreach ($json_resp['transactions'] as $transaction) {
if($transaction['related_resources']) {
$related_resource_count = count($transaction['related_resources']);
foreach ($transaction['related_resources'] as $related_resource) {
if($related_resource['authorization']){
$related_resources = $related_resources."authorization ";
$authorization = $related_resource['authorization'];
foreach ($authorization['links'] as $link) {
if($link['rel'] == 'self'){
$auth_detail_url = $link['href'];
$auth_detail_method = $link['method'];
}else if($link['rel'] == 'refund'){
$refund_url = $link['href'];
$refund_method = $link['method'];
}else if($link['rel'] == 'void'){
$void_url = $link['href'];
$void_method = $link['method'];
}else if($link['rel'] == 'capture'){
$capture_url = $link['href'];
$capture_method = $link['method'];
}
}
} else if($related_resource['refund']){
$related_resources = $related_resources."refund";
}
}
}
}
echo "Payment Created successfully: " . $json_resp['id'] ." with state '". $json_resp['state']."'<br>";
echo "Payment related_resources:". $related_resource_count . "(". $related_resources.")";
echo "<br> <br>";
echo "###########################################<br>";
echo "Obtaining Payment Details... <br>";
$json_resp = make_get_call($payment_detail_url);
echo "Payment details obtained for: " . $json_resp['id'] ." with state '". $json_resp['state']. "'";
echo "<br> <br>";
echo "###########################################<br>";
echo "Obtaining Authorization details...<br>";
$json_resp = make_get_call($auth_detail_url);
echo "Authorization details obtained for: " . $json_resp['id'] ." with state '". $json_resp['state']."'";
echo "<br> <br>";
echo "###########################################<br>";
echo "Capturing Authorization ...<br>";
$capture = array(
'amount' => array(
'total' => '5.47',
'currency' => 'USD'
)
);
$json = json_encode($capture);
$json_resp = make_post_call($capture_url, $json);
echo "Capture processed " . $json_resp['id'] ." with state '". $json_resp['state']."'";
foreach ($json_resp['links'] as $link) {
if($link['rel'] == 'self'){
$capture_detail_url = $link['href'];
$capture_detail_method = $link['method'];
}else if($link['rel'] == 'refund'){
$refund_url = $link['href'];
$refund_method = $link['method'];
}
}
echo "<br> <br>";
echo "###########################################<br>";
echo "Obtaining Authorization details...<br>";
$json_resp = make_get_call($auth_detail_url);
echo "Authorization details obtained for: " . $json_resp['id'] ." with state '". $json_resp['state']."'";
echo "<br> <br>";
echo "###########################################<br>";
echo "Obtaining Capture details...<br>";
$json_resp = make_get_call($capture_detail_url);
echo "Capture details obtained for: " . $json_resp['id'] ." with state '". $json_resp['state']."'";
echo "<br> <br>";
echo "###########################################<br>";
echo "Refunding a Capture... <br>";
$refund = array(
'amount' => array(
'total' => '2.47',
'currency' => 'USD'
)
);
$json = json_encode($refund);
$json_resp = make_post_call($refund_url, $json);
echo "Refund processed " . $json_resp['id'] ." with state '". $json_resp['state']."'";
echo "<br> <br>";
echo "###########################################<br>";
echo "Obtaining Capture details...<br>";
$json_resp = make_get_call($capture_detail_url);
echo "Capture details obtained for: " . $json_resp['id'] ." with state '". $json_resp['state']."'";
echo "<br> <br>";
echo "###########################################<br>";
echo "Voiding Authorization ...<br>";
$void = array();
$json = json_encode($void);
$json_resp = make_post_call($void_url, $json);
echo "Void processed " . $json_resp['id'] ." with state '". $json_resp['state']."'";
echo "<br> <br>";
echo "###########################################<br>";
echo "Obtaining Authorization details...<br>";
$json_resp = make_get_call($auth_detail_url);
echo "Authorization details obtained for: " . $json_resp['id'] ." with state '". $json_resp['state']."'";
echo "<br> <br>";
echo "###########################################<br>";
echo "Obtaining parent Payment Details for the Authorization ... <br>";
$json_resp = make_get_call($payment_detail_url);
$related_resource_count = 0;
$related_resources = "";
foreach ($json_resp['transactions'] as $transaction) {
if($transaction['related_resources']) {
$related_resource_count = count($transaction['related_resources']);
foreach ($transaction['related_resources'] as $related_resource) {
if($related_resource['authorization']){
$related_resources = $related_resources."authorization ";
} else if($related_resource['capture']){
$related_resources = $related_resources."capture ";
} else if($related_resource['refund']){
$related_resources = $related_resources."refund ";
}
}
}
}
echo "Payment details obtained for: " . $json_resp['id'] ." with state '". $json_resp['state']. "' <br>";
echo "Payment related_resources:". $related_resource_count . "(". $related_resources.")";
echo "<br> <br>";
die;
//END CREDIT CARD FUNCTIONS
//Paypal Payment
echo "###########################################<br>";
echo "Initiating a Payment with PayPal Account... <br>";
$url = $host.'/v1/payments/payment';
$payment = array(
'intent' => 'sale',
'payer' => array(
'payment_method' => 'paypal'
),
'transactions' => array (array(
'amount' => array(
'total' => '7.47',
'currency' => 'USD'
),
'description' => 'payment using a PayPal account'
)),
'redirect_urls' => array (
'return_url' => 'http://project.aimlessmedia.com/001/return.php?cancelled=0&returned=1',
'cancel_url' => 'http://project.aimlessmedia.com/001/return.php?cancelled=1&returned=1'
)
);
$json = json_encode($payment);
$json_resp = make_post_call($url, $json);
foreach ($json_resp['links'] as $link) {
if($link['rel'] == 'execute'){
$payment_execute_url = $link['href'];
$payment_execute_method = $link['method'];
} else if($link['rel'] == 'approval_url'){
$payment_approval_url = $link['href'];
$payment_approval_method = $link['method'];
}
}
echo "Payment Created successfully: " . $json_resp['id'] ." with state '". $json_resp['state']."'<br><br>";
echo "Please goto ".$payment_approval_url." in your browser and approve the payment with a PayPal Account.<br>";
echo "Enter PayerId from the return url to continue:";
$payerId = read_stdin();
echo "<br> <br>";
echo "###########################################<br>";
echo "Executing the PayPal Payment for PayerId (".$payerId.")... <br>";
$payment_execute = array(
'payer_id' => $payerId
);
$json = json_encode($payment_execute);
$json_resp = make_post_call($payment_execute_url, $json);
echo "Payment Execute processed " . $json_resp['id'] ." with state '". $json_resp['state']."'";
echo "<br> <br>";
?>
I believe credit card payments to a recipient's email is not supported as of yet.
Check here: https://developer.paypal.com/webapps/developer/docs/api/#errors (scroll down to "Validation Issues")
Specification of payee by email is not currently supported
You can’t currently use an email to indicate the payee.
Hi there all been trying to get this working for about 2 days now. The Payment is going through no problem but it not update the Database :(
Here is the Code :
<?php
require_once(WWW_DIR."/lib/users.php");
// Connect to database
$con = mysql_connect("localhost","root","******");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value)
{
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); // Test
//$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30); // Live
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$txn_id = $_POST['txn_id'];
$payer_email = $_POST['payer_email'];
$name = $_POST['first_name'] . " " . $_POST['last_name'];
$address_street = $_POST['address_street'];
$address_zip = $_POST['address_zip'];
$address_city = $_POST['address_city'];
$contact_phone = $_POST['contact_phone'];
$email = $_POST['payer_email'];
$uid = $users->currentUserId();
//timezone set
date_default_timezone_set('Europe/London');
if (!$fp)
{
// HTTP ERROR
} else
{
fputs($fp, $header . $req);
while (!feof($fp))
{
$res = fgets($fp, 1024);
if (strcmp($res, "VERIFIED") == 0) {
if($payment_status != "Completed"){
if($payment_amount == 2.00)
{
$role = 6;
}
else
if($payment_amount == 5.00)
{
$role = 8;
}
else
if($payment_amount == 8.00)
{
$role = 9;
}
//update user records
$sql = sprintf("UPDATE users SET role = %d WHERE ID = %d", $role, $uid);
mysql_query($sql);
//log payment
//mysql_query("INSERT INTO payments (email, item_name, payment_status, txn_id, payment_ammount) VALUES('" . mysql_escape_string($email) . "', '" . $item_name . "', '" . $payment_status . "', '" . $txn_id . "', '" . $payment_amount . "' ) ") or die(mysql_error());
}} else
if (strcmp($res, "INVALID") == 0)
{
// log for manual investigation
}
}
fclose($fp);
}
?>
If you have any Questions just ask I will try and Answer ASAP if you could get this working I would be very happy
Thanks
Change:
// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
To:
// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Host: www.sandbox.paypal.com\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n";
$header .= "Connection: close\r\n\r\n";
Change:
if (strcmp($res, "VERIFIED") == 0) {
To:
if (strcmp(trim($res), "VERIFIED") == 0) {
And lastly, change:
if (strcmp($res, "INVALID") == 0)
To:
if (strcmp(trim($res), "INVALID") == 0)
Reason:
The PayPal Sandbox is configured to reject HTTP 1.0 requests without a Host header specified, so your current script will never properly validate.
I have this simple php mail form. It is working and I can use it for making my forms, but I have a problem:
I want to add 2 or 3 attachments to this form. I tried a lot reading about mail at php.net, but I cannot do it by my self.
<?php
$name=$_POST['name'];
$email=$_POST['email'];
$address=$_POST['address'];
$phone=$_POST['phone'];
$fax=$_POST['fax'];
$mobile=$_POST['mobile'];
$subject=$_POST['subject'];
$website=$_POST['website'];
$message=$_POST['message'];
$fulltext = "
______________________________________________
|
| This Is $name Information:
|______________________________________________
| Name : $name
|______________________________________________
| E-Mail : $email
|______________________________________________
| Address : $address
|______________________________________________
| Phone : $phone
|______________________________________________
| FAX : $fax
|______________________________________________
| Mobile : $mobile
|______________________________________________
| Subject : $subject
|______________________________________________
| Website : $website
|______________________________________________
| Message : $message
|______________________________________________
";
$to = 'support#site.com';
$subject = 'Connect FORM <<';
$headers = 'From: contactform#site.com' . "\r\n" .
$message = $fulltext;
mail($to, $subject, $message, $headers);
echo 'file ersal shod';
?>
I improved code from http://ru.php.net/manual/ru/function.mail.php#105661 :
<?php
function multi_attach_mail($to, $subject, $message, $files, $sendermail){
// email fields: to, from, subject, and so on
$from = "Files attach <".$sendermail.">";
//$subject = date("d.M H:i")." F=".count($files);
$message .= "\n".count($files)." attachments";
$headers = "From: $from";
// boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
// multipart boundary
$message = "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
// preparing attachments
for($i=0;$i<count($files);$i++){
if(is_file($files[$i])){
$message .= "--{$mime_boundary}\n";
$fp = #fopen($files[$i],"rb");
$data = #fread($fp,filesize($files[$i]));
#fclose($fp);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: application/octet-stream; name=\"".basename($files[$i])."\"\n" .
"Content-Description: ".basename($files[$i])."\n" .
"Content-Disposition: attachment;\n" . " filename=\"".basename($files[$i])."\"; size=".filesize($files[$i]).";\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
}
}
$message .= "--{$mime_boundary}--";
$returnpath = "-f" . $sendermail;
$ok = #mail($to, $subject, $message, $headers, $returnpath);
if($ok){ return $i; } else { return 0; }
}
multi_attach_mail("to#somebody.dom",
"Subject of mail" ,
"Hello world!!!",
array($_SERVER["DOCUMENT_ROOT"] . "/first.file", // one file in root of your site
$_SERVER["DOCUMENT_ROOT"] . "/second.file" // another one
),
"from#someone");
?>