page has Too many redirects from mail.php file? - http-referer

I hope someone can help me. I have a page with a form and then the information
is emailed to me. the code below seems to be redirecting to the same page over and over again. It used to work for years now its not always working.
any help appreciated. Thanks Steve
<?php
//****************************************
//edit here
$senderName = 'WEB';
$senderEmail = 'site#example.com';
$targetEmail = 'contact#sellmydiabeticteststrips.com';
$messageSubject = 'Message from web-site';
$redirectToReferer = true;
$redirectURL = 'contact.html';
//****************************************
// mail content
$ufname = $_POST['ufname'];
$uaddress = $_POST['uaddress'];
$uemail = $_POST['uemail'];
$utel = $_POST['utel'];
$ucity = $_POST['ucity'];
$ustate = $_POST['ustate'];
$uzip = $_POST['uzip'];
$ubrand = $_POST['ubrand'];
$unumber = $_POST['unumber'];
$ucheck = $_POST['ucheck'];
$agree = $_POST['agree'];
// collect interests data
$interestsString = '';
for($i = 0; $i < count($interests); $i++) {
$interestsString .= $interests[$i].($i < count($interests) - 1 ? ', ' : '');
}
// prepare message text
$messageText = 'First Name: '.$ufname."\n".
'Address: '.$uaddress."\n".
'Email: '.$uemail."\n".
'Telephone: '.$utel."\n".
'City: '.$ucity."\n".
'State: '.$ustate."\n".
'Zip: '.$uzip."\n".
'Brand of test strips: '.$ubrand."\n".
'Number of boxes: '.$unumber."\n".
'Check: '.$ucheck."\n".
'Terms and Conditions: '.$agree."\n";
if($interestsString) {
$messageText .= 'Kinderen wonen bij mij: '.$interestsString."\n";
}
// send email
$senderName = "=?UTF-8?B?" . base64_encode($senderName) . "?=";
$messageSubject = "=?UTF-8?B?" . base64_encode($messageSubject) . "?=";
$messageHeaders = "From: " . $senderName . " <" . $senderEmail . ">\r\n"
. "MIME-Version: 1.0" . "\r\n"
. "Content-type: text/plain; charset=UTF-8" . "\r\n";
if (preg_match('/^[_.0-9a-z-]+#([0-9a-z][0-9a-z-]+.)+[a-z]{2,4}$/',$targetEmail,$matches))
mail($targetEmail, $messageSubject, $messageText, $messageHeaders);
// redirect
if($redirectToReferer) {
header("Location: ".#$_SERVER['HTTP_REFERER'].'#sent');
} else {
header("Location: ".$redirectURL);
}
?>

Related

Two forms with alert-box success, one works the other doesn't

I got an html template with a contact form from a site and I love it. I edited it to send the data to me, and it works. Once the user hits submit, the alert-box comes across the page indicating the message was sent. I need another form so I copied the original one, changed the name, edited the forms with the fields I need, copied the php file to one with a name that corresponds to my new form. The form works, I get the data however, instead of getting the alert-box, the page goes to a blank page with the url of the php file and the message "Thank you! We have received your message." I don't know what's wrong and why the alert box isn't working. Any help would be appreciated.
<?php
//Retrieve form data.
//GET - user submitted data using AJAX
//POST - in case user does not support javascript, we'll use POST instead
$full_name = ($_GET['full_name']) ? $_GET['full_name'] : $_POST['full_name'];
$h_address = ($_GET['h_address']) ?$_GET['h_address'] : $_POST['h_address'];
$h_city = ($_GET['h_city']) ?$_GET['h_city'] : $_POST['h_city'];
$h_state = ($_GET['h_state']) ?$_GET['h_state'] : $_POST['h_state'];
$h_zipcode = ($_GET['h_zipcode']) ?$_GET['h_zipcode'] : $_POST['h_zipcode'];
$h_phone_n = ($_GET['h_phone_n']) ?$_GET['h_phone_n'] : $_POST['h_phone_n'];
$c_phone_n = ($_GET['c_phone_n']) ?$_GET['c_phone_n'] : $_POST['c_phone_n'];
$h_email = ($_GET['h_email']) ?$_GET['h_email'] : $_POST['h_email'];
$w_fon_n1 = ($_GET['w_fon_n1']) ?$_GET['w_fon_n1'] : $_POST['w_fon_n1'];
$w_email = ($_GET['w_email']) ?$_GET['w_email'] : $_POST['w_email'];
$Voice = ($_GET['Voice']) ?$_GET['Voice'] : $_POST['Voice'];
$First_Second = ($_GET['First_Second']) ?$_GET['First_Second'] : $_POST['First_Second'];
$notify_by = ($_GET['notify_by']) ?$_GET['notify_by'] : $_POST['notify_by'];
$Experience = ($_GET['Experience']) ?$_GET['Experience'] : $_POST['Experience'];
//flag to indicate which method it uses. If POST set it to 1
if ($_POST) $post=1;
//Simple server side validation for POST data, of course, you should validate the email
if (!$full_name) $errors[count($errors)] = 'Please enter your full name.';
if (!$h_address) $errors[count($errors)] = 'Please enter your street address.';
if (!$h_city) $errors[count($errors)] = 'Please enter your city.';
if (!$h_state) $errors[count($errors)] = 'Please enter your state.';
if (!$h_zipcode) $errors[count($errors)] = 'Please enter your zipcode.';
if (!$h_phone_n) $errors[count($errors)] = 'Please enter your home phone.';
if (!$c_phone_n) $errors[count($errors)] = 'Please enter your cell phone.';
if (!$h_email) $errors[count($errors)] = 'Please enter your email.';
if (!$Voice) $errors[count($errors)] = 'Please enter your voice part.';
if (!$First_Second) $errors[count($errors)] = 'Please enter whether first or second.';
if (!notify_by) $errors[count($errors)] = 'Please enter how we should contact you.';
if (!$Experience) $errors[count($errors)] = 'Please enter your choral experience.';
//if the errors array is empty, send the mail
if (!$errors) {
//recipient - replace your email here
$to = 'mail#email.com';
//sender - from the form
$from = 'MCC Audition Request <webmaster#mendelssohnchoir.com>';
//subject and the html message
$subject = 'MCC Audition Request from ' . $full_name;
$message = 'FullName: ' . $full_name . '<br/><br/>
Address: ' . $h_address . '<br/><br/>
City: ' . $h_city . '<br/><br/>
State: ' . $h_state . '<br/><br/>
Zipcode: ' . $h_zipcode . '<br/><br/>
HPhone: ' . $h_phone_n . '<br/><br/>
HCell: ' . $c_phone_n . '<br/><br/>
HomeEmail: ' . $h_email . '<br/><br/>
WPhone: ' . $w_phone_n . '<br/><br/>
WEmail: ' . $w_email . '<br/><br/>
Voice: ' . $Voice . '<br/><br/>
Voicepart: ' . $First_Second . '<br/><br/>
NotifyBy: ' . $notify_by . '<br/><br/>
Message: ' . nl2br($Experience) . '<br/>';
//send the mail
$result = sendmail($to, $subject, $message, $from);
//if POST was used, display the message straight away
if ($_POST) {
if ($result) echo 'Thank you! We have received your message.';
else echo 'Sorry, unexpected error. Please try again later';
//else if GET was used, return the boolean value so that
//ajax script can react accordingly
//1 means success, 0 means failed
} else {
echo $result;
}
//if the errors array has values
} else {
//display the errors message
for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>';
echo 'Back';
exit;
}
//Simple mail function with HTML header
function sendmail($to, $subject, $message, $from) {
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$result = mail($to,$subject,$message,$headers);
if ($result) return 1;
else return 0;
}
?>

Integrate Authorize.net (Echeck.net) payment method in Magento 1.7.0.2

I need to integrate the Authorize.net (Echeck.net) payment method for my magento site.I have googled but i dont find Please suggest if there is any extensions for the payment method or else can we achieve this by coding.I am using magento 1.7.0.2.
Thanks in Advance!
The Official Beta release from authorize.net is available on Magento market(Magento Connect). This module is tested only in sandbox and currently in Beta status and probably compateble with 1.4 and 1.6. have not tried with 1.7 yet. you can try it if works. Please find the module at following link
http://www.magentocommerce.com/magento-connect/echeck-payment-method-authorize-net.html
If you need to customise the extention feel free to contact at contact#sgssandhu.com or http://oxosolutions.com/
Thanks
Hi here is working example of ECHECK through curl request & parsing of Response with delimiter:
public function curlProcessECHECK(){
$query = "";
// Login Information
$query .= "x_login=" . urlencode($this->credentials->username) . "&";
$query .= "x_tran_key=" . urlencode($this->credentials->password) . "&";
$query .= "x_version=" . "3.1" . "&";
$query .= "x_delim_data=" . "TRUE" . "&";
$query .= "x_delim_char=" . "|" . "&";
$query .= "x_relay_response=" . "FALSE" . "&";
$query .= "x_amount=" . urlencode(number_format($data['orderTotalAmt'], 2, ".", "")) . "&";
// ECHECk payments..... code to check ECHECK request
switch ($data['bank_acct_type'])
{
case 'checking':
$echecktype = 'PPD';
break;
case 'businessChecking':
$echecktype = 'CCD';
break;
case 'savings':
$echecktype = 'PPD';
break;
default:
$echecktype = 'PPD';
break;
}
$query .= "x_method=ECHECK&";
$query .= "x_bank_name=" . urlencode($data['bank_name']) . "&";
$query .= "x_echeck_type=" . urlencode($echecktype) . "&"; //CCD, PPD, TEL ---[ARC, BOC]- bank_check_number ll be required, [WEB] recurring_billing ll be required.
$query .= "x_bank_acct_type=" . urlencode($data['bank_acct_type']) . "&";
$query .= "x_bank_acct_num=" . urlencode($data['bank_acct_num']) . "&";
$query .= "x_bank_aba_code=" . urlencode($data['bank_aba_code']) . "&"; // aba code should be valid get from google US based banks
$query .= "x_bank_acct_name=" . urlencode($data['bank_acct_name']) . "&";
$query .= "x_description=" . (isset($data['orderDescription']) ? urlencode($data['orderDescription']) : "") . "&";
$query .= "x_first_name=" . (isset($data['billingFirstName']) ? urlencode($data['billingFirstName']) : $data['firstName']) . "&";
$query .= "x_last_name=" . (isset($data['billingLastName']) ? urlencode($data['billingLastName']) : $data['lastName']) . "&";
$query .= "x_address=" . (isset($data['billingAddress1']) ? urlencode($data['billingAddress1']) : "") . "&";
$query .= "x_state=" . (isset($data['billingState']) ? urlencode($data['billingState']) : "") . "&";
$query .= "x_zip=" . (isset($data['billingZip']) ? urlencode($data['billingZip']) : "") . "&";
if($this->env == 1) {
$query .= "x_test_request=TRUE&";
}
$query .= "x_type=AUTH_CAPTURE";
$output = array();
$url = 'https://test.authorize.net/gateway/transact.dll';// TestMode
$ch_response = null;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
$ch_response = curl_exec($ch);
// Check that a connection was made
if (curl_error($ch)) {
// If it wasn't...
$output['status'] = "Failure";
$output['response']['code'] = '-1';
$output['data'] = null;
$output['response']['responseMsg'] = curl_error($ch);
$output['response']['gateway_response_code'] ='000';
$output['response']['responsetext']= " No response from gateway";
$output['response']['transactionid'] = '';
$output['response']['init'] ="no";
$output['response']['response_code']='000';
} else {
$output['status'] = 'Success';
$output['data'] = $ch_response;
$output = $this->processResponse($output);
}
echo '<pre>';print_r($output);die;
}
Now parse the result
public function processResponse($output){
$response_array=$output;
if ($response_array) {
// Split Array
$encap_char = "|";
$response_array = explode($encap_char, $response_array['data']);
//echo"<pre>";print_r($response_array);die;
/**
* If AuthorizeNet doesn't return a delimited response.
*/
if (count($response_array) < 10) {
$approved = false;
$error = true;
$error_message = "Unrecognized response from AuthorizeNet: ";
return;
}
// Set all fields
$response_code = $response_array[0];
$response_subcode = $response_array[1];
$response_reason_code = $response_array[2];
$response_reason_text = $response_array[3];
$authorization_code = $response_array[4];
$avs_response = $response_array[5];
$transaction_id = $response_array[6];
$invoice_number = $response_array[7];
$description = $response_array[8];
$amount = $response_array[9];
$method = $response_array[10];
$transaction_type = $response_array[11];
$customer_id = $response_array[12];
$first_name = $response_array[13];
$last_name = $response_array[14];
$company = $response_array[15];
$address = $response_array[16];
$city = $response_array[17];
$state = $response_array[18];
$zip_code = $response_array[19];
$country = $response_array[20];
$phone = $response_array[21];
$fax = $response_array[22];
$email_address = $response_array[23];
$ship_to_first_name = $response_array[24];
$ship_to_last_name = $response_array[25];
$ship_to_company = $response_array[26];
$ship_to_address = $response_array[27];
$ship_to_city = $response_array[28];
$ship_to_state = $response_array[29];
$ship_to_zip_code = $response_array[30];
$ship_to_country = $response_array[31];
$tax = $response_array[32];
$duty = $response_array[33];
$freight = $response_array[34];
$tax_exempt = $response_array[35];
$purchase_order_number = $response_array[36];
$md5_hash = $response_array[37];
$card_code_response = $response_array[38];
$cavv_response = $response_array[39];
$account_number = $response_array[50];
$card_type = $response_array[51];
$split_tender_id = $response_array[52];
$requested_amount = $response_array[53];
$balance_on_card = $response_array[54];
// $approved = ($response_code == self::APPROVED);
// $declined = ($response_code == self::DECLINED);
// $error = ($response_code == self::ERROR);
// $held = ($response_code == self::HELD);
$approved = "";
$declined = "";
$error = "";
$held = "";
if ($response_code == 1) {
$result['response']['response_code'] = 100;
$result['response']['gateway_response_code'] = 100;
$result['response']['responsetext'] = "Success";
$result['status'] = 'success';
} elseif ($response_code == 2) {
$result['response']['response_code'] = 800;
$result['response']['gateway_response_code'] = 800;
$result['response']['responsetext'] = "Declined";
$result['status'] = $response_reason_text;
} else {
$result['response']['response_code'] = $response_code;
$result['response']['gateway_response_code'] = $response_code;
$result['response']['responsetext'] = $response_reason_text;
$result['status'] = $response_reason_text;
}
$result['method'] = $method;
$result['md5_hash'] = $md5_hash;
$result['card_type'] = $card_type;
$result['account_number'] = $account_number;
$result['response']['transactionid'] = $transaction_id;
$result['response']['processor_id'] = "";
$result['response']['cvvresponse'] = $cavv_response;
$result['response']['avsresponse'] = $avs_response;
$result['response']['authcode'] = $authorization_code;
$result['response']['type'] = "Sale";
$result['response']['init'] = "no";
return $result;
}
}

Php form redirect to thank you page

I'd like to use this free form template but I want it to redirect me to a thank you page upon submission.
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "e-mail here";
$email_subject = "subject here";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
How can I add a code where I will be redirected to a page of my choice?
header("Location: http://page_of_your_choice.com");
Just insert this where you have the
<!-- include your own success html here -->

PAY PAL IPN stop working

My code stop working, I have made some changes like $res=trim($res); as I saw in another question but still not working.
The code was perfectly working including automatic post in Facebook and Tweeter.
Please, could someone check my code and help me to fix it?
<?php
// Revision Notes
// 11/04/11 - changed post back url from https://www.paypal.com/cgi-bin/webscr to https://ipnpb.paypal.com/cgi-bin/webscr
// For more info see below:
// https://www.x.com/content/bulletin-ip-address-expansion-paypal-services
// "ACTION REQUIRED: if you are using IPN (Instant Payment Notification) for Order Management and your IPN listener script is behind a firewall that uses ACL (Access Control List) rules which restrict outbound traffic to a limited number of IP addresses, then you may need to do one of the following:
// To continue posting back to https://www.paypal.com to perform IPN validation you will need to update your firewall ACL to allow outbound access to *any* IP address for the servers that host your IPN script
// OR Alternatively, you will need to modify your IPN script to post back IPNs to the newly created URL https://ipnpb.paypal.com using HTTPS (port 443) and update firewall ACL rules to allow outbound access to the ipnpb.paypal.com IP ranges (see end of message)."
/////////////////////////////////////////////////
/////////////Begin Script below./////////////////
/////////////////////////////////////////////////
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i','${1}%0D%0A${3}',$value);// IPN fix
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Host: www.paypal.com\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\r\n";
// If testing on Sandbox use:
//$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
$fp = fsockopen ('ssl://ipnpb.paypal.com', 443, $errno, $errstr, 30);
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$business = $_POST['business'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$mc_gross = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$receiver_id = $_POST['receiver_id'];
$quantity = $_POST['quantity'];
$num_cart_items = $_POST['num_cart_items'];
$payment_date = $_POST['payment_date'];
$first_name = $_POST['fir st_name'];
$last_name = $_POST['last_name'];
$payment_type = $_POST['payment_type'];
$payment_status = $_POST['payment_status'];
$payment_gross = $_POST['payment_gross'];
$payment_fee = $_POST['payment_fee'];
$settle_amount = $_POST['settle_amount'];
$memo = $_POST['memo'];
$payer_email = $_POST['payer_email'];
$txn_type = $_POST['txn_type'];
$payer_status = $_POST['payer_status'];
$address_street = $_POST['address_street'];
$address_city = $_POST['address_city'];
$address_state = $_POST['address_state'];
$address_zip = $_POST['address_zip'];
$address_country = $_POST['address_country'];
$address_status = $_POST['address_status'];
$item_number = $_POST['item_number'];
$tax = $_POST['tax'];
$option_name1 = $_POST['option_name1'];
$option_selection1 = $_POST['option_selection1'];
$option_name2 = $_POST['option_name2'];
$option_selection2 = $_POST['option_selection2'];
$for_auction = $_POST['for_auction'];
$invoice = $_POST['invoice'];
$custom = $_POST['custom'];
$notify_version = $_POST['notify_version'];
$verify_sign = $_POST['verify_sign'];
$payer_business_name = $_POST['payer_business_name'];
$payer_id =$_POST['payer_id'];
$mc_currency = $_POST['mc_currency'];
$mc_fee = $_POST['mc_fee'];
$exchange_rate = $_POST['exchange_rate'];
$settle_currency = $_POST['settle_currency'];
$parent_txn_id = $_POST['parent_txn_id'];
$pending_reason = $_POST['pending_reason'];
$reason_code = $_POST['reason_code'];
// subscription specific vars
$subscr_id = $_POST['subscr_id'];
$subscr_date = $_POST['subscr_date'];
$subscr_effective = $_POST['subscr_effective'];
$period1 = $_POST['period1'];
$period2 = $_POST['period2'];
$period3 = $_POST['period3'];
$amount1 = $_POST['amount1'];
$amount2 = $_POST['amount2'];
$amount3 = $_POST['amount3'];
$mc_amount1 = $_POST['mc_amount1'];
$mc_amount2 = $_POST['mc_amount2'];
$mc_amount3 = $_POST['mcamount3'];
$recurring = $_POST['recurring'];
$reattempt = $_POST['reattempt'];
$retry_at = $_POST['retry_at'];
$recur_times = $_POST['recur_times'];
$username = $_POST['username'];
$password = $_POST['password'];
//auction specific vars
$for_auction = $_POST['for_auction'];
$auction_closing_date = $_POST['auction_closing_date'];
$auction_multi_item = $_POST['auction_multi_item'];
$auction_buyer_id = $_POST['auction_buyer_id'];
//DB connect creds and email
$notify_email = "xxxxxx#gmail.com"; //email address to which debug emails are sent to
$DB_Server = "localhost"; //your MySQL Server
$DB_Username = "xxxxx"; //your MySQL User Name
$DB_Password = "xxxxx"; //your MySQL Password
$DB_DBName = "xxxxx"; //your MySQL Database Name
if (!$fp)
{
// HTTP ERROR
}
else
{
fputs ($fp, $header . $req);
while (!feof($fp))
{
$res = fgets ($fp, 1024);
$res=trim($res);
if (strcmp ($res, "VERIFIED") == 0)
//if (strcmp ($res, "VERIFIED\r\n") == 0)
{
//create MySQL connection
$Connect = #mysql_connect($DB_Server, $DB_Username, $DB_Password)
or die("Couldn't connect to MySQL:<br>" . mysql_error() . "<br>" . mysql_errno());
//select database
$Db = #mysql_select_db($DB_DBName, $Connect)
or die("Couldn't select database:<br>" . mysql_error(). "<br>" . mysql_errno());
$fecha = date("m")."/".date("d")."/".date("Y");
$fecha = date("Y").date("m").date("d");
//check if transaction ID has been processed before
$checkquery = "select txnid from paypal_payment_info where txnid='".$txn_id."'";
$sihay = mysql_query($checkquery) or die("Duplicate txn id check query failed:<br>" . mysql_error() . "<br>" . mysql_errno());
$nm = mysql_num_rows($sihay);
if ($nm == 0)
{
//execute query
$strQuery = "insert into paypal_payment_info(paymentstatus,buyer_email,receiver_email,firstname,lastname,street,city,state,zipcode,country,mc_gross,mc_fee,quantity,memo,paymenttype,paymentdate,txnid,pendingreason,reasoncode,tax,datecreation) values ('".$payment_status."','".$payer_email."','".$receiver_email."','".$first_name."','".$last_name."','".$address_street."','".$address_city."','".$address_state."','".$address_zip."','".$address_country."','".$mc_gross."','".$mc_fee."','".$quantity."','".$memo."','".$payment_type."','".$payment_date."','".$txn_id."','".$pending_reason."','".$reason_code."','".$tax."','".$fecha."')";
$result = mysql_query("insert into paypal_payment_info(paymentstatus,buyer_email,receiver_email,firstname,lastname,street,city,state,zipcode,country,mc_gross,mc_fee,quantity,memo,paymenttype,paymentdate,txnid,pendingreason,reasoncode,tax,datecreation) values ('".$payment_status."','".$payer_email."','".$receiver_email."','".$first_name."','".$last_name."','".$address_street."','".$address_city."','".$address_state."','".$address_zip."','".$address_country."','".$mc_gross."','".$mc_fee."','".$quantity."','".$memo."','".$payment_type."','".$payment_date."','".$txn_id."','".$pending_reason."','".$reason_code."','".$tax."','".$fecha."')")
or die("Default - paypal_payment_info, Query failed:<br>" . mysql_error() . "<br>" . mysql_errno());
{
$consumerKey = 'ccYgLrtBUrgIPJDQ';
$consumerSecret = '4qXLLXdQPcKqAqKscYQH9p9m3cznyVWYc4v8';
$oAuthToken = 'uVgkQTC0BLNT9V9vTpc25poxDgIomCgMbw';
$oAuthSecret = 'L8rfc6A1Ii5cMeuYEhf6hwkc3aATyo';
require_once('twitteroauth.php');
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthSecret);
$tweet->post('statuses/update', array('status' => 'Last donation US$ '.$mc_gross.' to '.$item_name.' '));
}
mail($notify_email, "VERIFIED IPN", "$res\n $req\n $strQuery\n $struery\n $strQuery2");
$sql = mysql_query(" UPDATE cadastros SET amount='$mc_gross'-'$mc_fee'+amount, mc_gross = '$mc_gross' , mc_fee ='$mc_fee', payment_date = '$payment_date',pay_date = now() WHERE receiver_email='$receiver_email'");
$result = mysql_query($sql) or die( mysql_error() );
}
else
{
// send an email
mail($notify_email, "VERIFIED DUPLICATED TRANSACTION", "$res\n $req\n $strQuery\n $struery\n $strQuery2");
}
// if the IPN POST was 'INVALID'...do this
}
else if (strcmp ($res, "INVALID") == 0)
{
// log for manual investigation
mail($notify_email, "INVALID IPN", "$res\n $req");
}
}
fclose ($fp);
}
?>
The HOST tag in the header has to match the URL you are using with fsockopen.
Try this:
$sandbox = 1;
$paypalURL = $sandbox ? 'www.sandbox.paypal.com' : 'www.paypal.com';
// Create http header
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n";
$header .= "Host: $paypalURL\r\n";
$header .= "Connection: close\r\n\r\n";
// Post back to PayPal system to verify
$fp = fsockopen('ssl://'.$paypalURL, 443, $errno, $errstr, 30);

Unable to send HTML mail through mail()

The mail sent by the below code includes all the HTML tags. How can I get rid of that tried a few ways but still mail output is scrambled with html tags. And also need help on if any better way of sending array of elements through mail();
My code:
<?php
include('Mail.php');
include('mail\mime.php');
$errors=array();
if(empty ($_POST)===false)
{
//$product = $_POST['product'];
//$quantity = $_POST['quantity'] ;
$email="noreply#cortexonline.in";
$item1 = $_POST['product']['1'];
$item2 = $_POST['product']['2'];
$item3 = $_POST['product']['3'];
$item4 = $_POST['product']['4'];
$item5 = $_POST['product']['5'];
$quan1 = $_POST['quantity']['1'];
$quan2 = $_POST['quantity']['2'];
$quan3 = $_POST['quantity']['3'];
$quan4 = $_POST['quantity']['4'];
$quan5 = $_POST['quantity']['5'];
$message = "<html><head><title></title>
</head> <body> <table>
<tr><td>Shop id=</td>
</tr><tr><td>Product Name</td>
<td>Quantity</td></tr>
<tr><td>".$item1."</td>
<td>".$quan1."</td></tr>
<tr><td>".$item2."</td>
<td>".$quan2."</td></tr>
<tr><td>".$item3."</td>
<td>".$quan3."</td></tr>
<tr><td>".$item4."</td>
<td>".$quan4."</td><td>".$item5."</td><td>".$quan5."</td></tr>
</table></body></html>";
$header = 'From: "Quick order" <noreply#cort.in>'.PHP_EOL.
'Reply-to: <noreply#cort.in>'.PHP_EOL.
'MIME-Version: 1.0'.PHP_EOL.
'Content-Type: text/plain; charset=utf-8'.PHP_EOL.
'Content-Transfer-Encoding: 8bit'.PHP_EOL.
'X-Mailer: PHP/'.PHP_VERSION.PHP_EOL;
if(ctype_alpha($quan1)===true||ctype_alpha($quan2)===true||ctype_alpha($quan3)==true||ctype_alpha($quan4)===true||ctype_alpha($quan5)===true)
{
$errors[]=' Quantity cannot be alphabet /n
Cannot send request';
}
if(isset($_POST['send'])===true)
{
if (empty($errors)===false)
{
echo '<script language="javascript">alert("NOT SENT! Qunatity cannot be Alphabet")</script>';
}
else
{
mail('order#cortexonline.in','Quick order',$message,$header);
echo '<script language="javascript">alert("Your order sent!")</script>';
echo '<script language="javascript">window.location = "index.php"</script>';
}
}
else
{
echo '<script language="javascript">alert("ORDER NOT SENT! Please Try Again.")</script>';
echo '<script language="javascript">window.location = "index.php"</script>';
}
}
?>
Also tried using single quotes it is not working.
Try this:
$header = 'From: "Quick order" <noreply#cort.in>'.PHP_EOL.
'Reply-to: <noreply#cort.in>'.PHP_EOL.
'MIME-Version: 1.0'.PHP_EOL.
'Content-Type: text/html; charset=utf-8'.PHP_EOL.
'Content-Transfer-Encoding: 8bit'.PHP_EOL.
'X-Mailer: PHP/'.PHP_VERSION.PHP_EOL;