Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Tell A Friend Form Sends Email To The Sender Instead Of The Recipient!


ali_razorback

Recommended Posts

Posted

Hello! I am currently testing the 'Tell A Friend About Site Too' contribution with some pretend accounts, and instead of the email being sent to the email address in the "Your Friend's Email Address:" box, it is infact sent to "Your Email Address:" i.e. the person sending the email! And I do still get a 'success' banner across the top.

 

Also, the email title doesn't appear as "Your friend %s has recommended this great product from %s", it is instead titled 'Tell A Friend'.

 

Any help on these two issues would be much appreciated! I've looked through the forums but couldn't find anything similar, but if a solution has been found perhaps you could reply with a link to it.

 

I am also using STS (where the code edit in the readme for this contribution should take place in includes/modules/sts_inc/sts_column_left.php instead of includes/column_right.php for those with that problem).

 

Have included the codes below, thanks!

 

 

Alice

 

 

 

 

Code For catalog/tell_a_friend.php

 

<?php
/*
 $Id: tell_a_friend.php,v 1.42999 moded by Buster 2003/11/08 21:45:01 hpdl Exp $

 5 march 2006 modified by A.S. Kerkmeester www.flashbios.org

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

require('includes/application_top.php');

if (!tep_session_is_registered('customer_id') && (ALLOW_GUEST_TO_TELL_A_FRIEND == 'false')) {
$navigation -> set_snapshot();
tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
}

$valid_product = false;
if (isset($HTTP_GET_VARS['products_id'])) {
if ($HTTP_GET_VARS['products_id'] == false ) {
	$valid_product = true;
} else {
	$product_info_query = tep_db_query("select pd.products_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'");
	if (tep_db_num_rows($product_info_query)) {
		$valid_product = true;
		$product_info = tep_db_fetch_array($product_info_query);
	}
}
}

if ($valid_product == false) {
tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_GET_VARS['products_id']));
}

require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_TELL_A_FRIEND);

if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'process')) {
$error = false;

// MESSAGE STACK FIX for new variable $tellAboutWhat
if ($HTTP_GET_VARS['products_id'] == false) {
$tellAboutWhat = STORE_NAME;
} else {
$tellAboutWhat = $product_info['products_name'];
}
// END MESSAGE STACK FIX for $tellAboutWhat

$to_email_address = tep_db_prepare_input($HTTP_POST_VARS['to_email_address']);
$to_name = tep_db_prepare_input($HTTP_POST_VARS['to_name']);
$from_email_address = tep_db_prepare_input($HTTP_POST_VARS['from_email_address']);
$from_name = tep_db_prepare_input($HTTP_POST_VARS['from_name']);
$message = tep_db_prepare_input($HTTP_POST_VARS['message']);

if (empty($from_name)) {
	$error = true;

	$messageStack -> add('friend', ERROR_FROM_NAME);
}

if (!tep_validate_email($from_email_address)) {
	$error = true;

	$messageStack -> add('friend', ERROR_FROM_ADDRESS);
}

if (empty($to_name)) {
	$error = true;

	$messageStack -> add('friend', ERROR_TO_NAME);
}

if (!tep_validate_email($to_email_address)) {
	$error = true;

	$messageStack -> add('friend', ERROR_TO_ADDRESS);
}

if ($error == false) {
	// ADDED THIS ALT SUBJECT FOR NON PRODUCT RECOMMENDATION
	if ($HTTP_GET_VARS['products_id'] == false) {
		$myEmailSubject = BOX_TELL_A_FRIEND_SUBJECT;
		$email_subject = sprintf($myEmailSubject, $from_name, STORE_NAME);
		$myEmailIntro = BOX_TELL_A_FRIEND_EMAILINTRO;
		$email_body = sprintf($myEmailIntro, $to_name, $from_name, STORE_NAME) . "\n\n";
		if (tep_not_null($message)) {
			$email_body .= $message . "\n\n";
		}
		$email_body .= BOX_TELL_A_FRIEND_BODY . "\n\n" . HTTP_SERVER . "\n\n" .
		sprintf(TEXT_EMAIL_SIGNATURE, STORE_NAME . "\n" . HTTP_SERVER . DIR_WS_CATALOG . "\n");
	} else {
		$email_subject = sprintf(TEXT_EMAIL_SUBJECT, $from_name, STORE_NAME);
		$email_body = sprintf(TEXT_EMAIL_INTRO, $to_name, $from_name, $product_info['products_name'], STORE_NAME) . "\n\n";
		if (tep_not_null($message)) {
			$email_body .= $message . "\n\n";
		}
		$email_body .= sprintf(TEXT_EMAIL_LINK, tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_GET_VARS['products_id'])) . "\n\n" .
		sprintf(TEXT_EMAIL_SIGNATURE, STORE_NAME . "\n" . HTTP_SERVER . DIR_WS_CATALOG . "\n");
	}
tep_mail($to_name, $to_email_address, $email_subject, $email_body, $from_name, $from_email_address);
// UNCOMMENT NEXT LINE ONLY IF YOU WANT THE ADDED FEATURE OF HAVING THE MAIL SENT TO THE SHOPOWNER!
tep_mail($to_name, STORE_OWNER_EMAIL_ADDRESS, BOX_TELL_A_FRIEND_MAILSUBJECT, $email_body, $from_name, $from_email_address);
$messageStack -> add_session('header', sprintf(TEXT_EMAIL_SUCCESSFUL_SENT, $tellAboutWhat, tep_output_string_protected($to_name)), 'success');
// Replaced above $HTTP_POST_VARS['products_name'] with $tellAboutWhat
// If prduct id is in the url then redirect back to product, otherwise redirect to home page
if ($HTTP_GET_VARS['products_id'] == false) {
	tep_redirect(tep_href_link(FILENAME_DEFAULT));
} else {
	tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_GET_VARS['products_id']));
} //END CHANGE IN LINK
}
} elseif (tep_session_is_registered('customer_id')) {
$account_query = tep_db_query("select customers_firstname, customers_lastname, customers_email_address from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$customer_id . "'");
$account = tep_db_fetch_array($account_query);

$from_name = $account['customers_firstname'] . ' ' . $account['customers_lastname'];
$from_email_address = $account['customers_email_address'];
}

$breadcrumb -> add(NAVBAR_TITLE, tep_href_link(FILENAME_TELL_A_FRIEND, 'products_id=' . $HTTP_GET_VARS['products_id']));

?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="3" cellpadding="3">
 <tr>
<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
</table></td>
<!-- body_text //-->
<td width="100%" valign="top"><?php echo tep_draw_form('email_friend', tep_href_link(FILENAME_TELL_A_FRIEND, 'action=process&products_id=' . $HTTP_GET_VARS['products_id'])); ?>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
	<td><table border="0" width="100%" cellspacing="0" cellpadding="0">
	  <tr>
		<td class="pageHeading">
<?php // NOTE THIS VAR USED SEVERAL TIMES BELOW
if ($HTTP_GET_VARS['products_id'] == false) {
$tellAboutWhat = STORE_NAME;
} else {
$tellAboutWhat = $product_info['products_name'];
}
echo sprintf(HEADING_TITLE, $tellAboutWhat);

?>
</td>
  <td class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES . 'table_background_contact_us.gif', sprintf(HEADING_TITLE, $tellAboutWhat), HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
	  </tr>
	</table></td>
  </tr>
  <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
  </tr>
<?php if ($messageStack -> size('friend') > 0) {

?>
  <tr>
	<td><?php echo $messageStack -> output('friend'); ?></td>
  </tr>
  <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
  </tr>
<?php
}
?>
  <tr>
	<td><table border="0" width="100%" cellspacing="0" cellpadding="2">
	  <tr>
		<td><table border="0" width="100%" cellspacing="0" cellpadding="2">
		  <tr>
			<td class="main"><b><?php echo FORM_TITLE_CUSTOMER_DETAILS; ?></b></td>
			<td class="inputRequirement" align="right"><?php echo FORM_REQUIRED_INFORMATION; ?></td>
		  </tr>
		</table></td>
	  </tr>
	  <tr>
		<td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
		  <tr class="infoBoxContents">
			<td><table border="0" cellspacing="0" cellpadding="2">
			  <tr>
				<td class="main"><?php echo FORM_FIELD_CUSTOMER_NAME; ?></td>
				<td class="main"><?php echo tep_draw_input_field('from_name'); ?></td>
			  </tr>
			  <tr>
				<td class="main"><?php echo FORM_FIELD_CUSTOMER_EMAIL; ?></td>
				<td class="main"><?php echo tep_draw_input_field('from_email_address'); ?></td>
			  </tr>
			</table></td>
		  </tr>
		</table></td>
	  </tr>
	  <tr>
		<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
	  </tr>
	  <tr>
		<td class="main"><b><?php echo FORM_TITLE_FRIEND_DETAILS; ?></b></td>
	  </tr>
	  <tr>
		<td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
		  <tr class="infoBoxContents">
			<td><table border="0" cellspacing="0" cellpadding="2">
			  <tr>
				<td class="main"><?php echo FORM_FIELD_FRIEND_NAME; ?></td>
				<td class="main"><?php echo tep_draw_input_field('to_name') . ' <span class="inputRequirement">' . ENTRY_FIRST_NAME_TEXT . '</span>'; ?></td>
			  </tr>
			  <tr>
				<td class="main"><?php echo FORM_FIELD_FRIEND_EMAIL; ?></td>
				<td class="main"><?php echo tep_draw_input_field('to_email_address') . ' <span class="inputRequirement">' . ENTRY_EMAIL_ADDRESS_TEXT . '</span>'; ?></td>
			  </tr>
			</table></td>
		  </tr>
		</table></td>
	  </tr>
	  <tr>
		<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
	  </tr>
	  <tr>
		<td class="main"><b><?php echo FORM_TITLE_FRIEND_MESSAGE; ?></b></td>
	  </tr>
	  <tr>
		<td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
		  <tr class="infoBoxContents">
			<td><?php echo tep_draw_textarea_field('message', 'soft', 40, 8); ?></td>
		  </tr>
		</table></td>
	  </tr>
	</table></td>
  </tr>
  <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
  </tr>
  <tr>
	<td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
	  <tr class="infoBoxContents">
		<td><table border="0" width="100%" cellspacing="0" cellpadding="2">
		  <tr>
			<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
			<td>
<?php if ($HTTP_GET_VARS['products_id'] == false) {
$pageTo = FILENAME_DEFAULT;
} else {
$pageTo = FILENAME_PRODUCT_INFO . '?products_id=' . $HTTP_GET_VARS['products_id'];
}
echo '<a href="' . tep_href_link($pageTo) . '">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; ?></td>
			<td align="right"><?php echo tep_image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE); ?></td>
			<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
		  </tr>
		</table></td>
	  </tr>
	</table></td>
  </tr>
</table></form></td>
<!-- body_text_eof //-->
<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- right_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>
<!-- right_navigation_eof //-->
</table></td>
 </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

 

 

 

 

 

 

 

Code for catalog/includes/languages/english/tell_a_friend.php

 

<?php
/*
 $Id: tell_a_friend.php,v 1.7 2003/06/10 18:20:39 hpdl Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

define('NAVBAR_TITLE', 'Tell A Friend');

define('HEADING_TITLE', 'Tell A Friend About: %s');

define('FORM_TITLE_CUSTOMER_DETAILS', 'Your Details');
define('FORM_TITLE_FRIEND_DETAILS', 'Your Friend\'s Details');
define('FORM_TITLE_FRIEND_MESSAGE', 'Your Message');

define('FORM_FIELD_CUSTOMER_NAME', 'Your Name:');
define('FORM_FIELD_CUSTOMER_EMAIL', 'Your Email Address:');
define('FORM_FIELD_FRIEND_NAME', 'Your Friend\'s Name:');
define('FORM_FIELD_FRIEND_EMAIL', 'Your Friend\'s Email Address:');

define('TEXT_EMAIL_SUCCESSFUL_SENT', 'Your email about <b>%s</b> has been successfully sent to <b>%s</b>.');

define('TEXT_EMAIL_SUBJECT', 'Your friend %s has recommended this great product from %s');
define('TEXT_EMAIL_INTRO', 'Hi %s!' . "\n\n" . 'Your friend, %s, thought that you would be interested in %s from %s.');
define('TEXT_EMAIL_LINK', 'To view the product, click on the link below ,or copy and paste the link into your web browser:' . "\n\n" . '%s');
define('TEXT_EMAIL_SIGNATURE', 'Kind regards,' . "\n\n" . '%s');

define('ERROR_TO_NAME', 'Error: Your friend\'s name must be entered.');
define('ERROR_TO_ADDRESS', 'Error: Your friend\'s email address must be a valid email address.');
define('ERROR_FROM_NAME', 'Error: Your name must be entered.');
define('ERROR_FROM_ADDRESS', 'Error: Your email address must be a valid email address.');

// new additions by Arthur Kerkmeester (www.flashios.org)
define('BOX_TELL_A_FRIEND_TEXT2', '<br />Why not email this page to a friend?');
define('BOX_TELL_A_FRIEND_SUBJECT', 'Your friend %s would like you to visit %s');
define('BOX_TELL_A_FRIEND_EMAILINTRO', 'Hello %s,' . "\n\n" . 'Your friend %s found a great site called %s and thought you\'d like to check it out!');
define('BOX_TELL_A_FRIEND_BODY','To view the page, click on the link below, or copy and paste the link into your web browser:');
define('BOX_TELL_A_FRIEND_MAILSUBJECT','Tell A Friend');
?>

Posted

The code looks fine to me. Try it with two different email addresses and see what the result is.

Please use the forums for support! I am happy to help you here, but I am unable to offer free technical support over instant messenger or e-mail.

Posted

Hello again!

 

Thanks for your quick reply.

 

I've tried another trial account I created, and I have discovered that it isn't 100% as stated in my first post - the emails are not going to the sender of the 'tell a friend' form, they are going to my email address, i.e. the one that I have entered as the 'store owner' under admin -- configuration -- my store.

 

I have this same email address ([email protected]) entered under 'e-mail address' and 'email from' in the configuration section. Perhaps this is incorrect? Although I can't see why the form would be sent to the store owner's address and not the person who it's supposed to be going to!

 

What an oddity hehe.

 

This is a great feature for the shop, so am desparate to get it working!

 

If you'd like to know any specific settings that I have that I should post here let me know and I'll get them written up.

 

Thanks ever so much again!

 

 

 

Alice

Posted

The code is correct. To disable it from sending you a copy of the email, change this line:

 

tep_mail($to_name, STORE_OWNER_EMAIL_ADDRESS, BOX_TELL_A_FRIEND_MAILSUBJECT, $email_body, $from_name, $from_email_address);

 

to:

//tep_mail($to_name, STORE_OWNER_EMAIL_ADDRESS, BOX_TELL_A_FRIEND_MAILSUBJECT, $email_body, $from_name, $from_email_address);

Please use the forums for support! I am happy to help you here, but I am unable to offer free technical support over instant messenger or e-mail.

Posted

Hiya!

 

Thanks for that little bit of code, I'll use that!

 

After even more testing (running out of email addresses to try this on!) it would appear that it wasn't liking the hotmail email accounts, I will have a search through the forum now for any solutions to these emails going through as spam into their junk email folders, or being completely blocked!

 

For anyone else who is unsure of this 'tell a friend' business - the system automatically sends you a copy of the 'tell a friend' email when someone uses it. The title of the email you recieve is 'Tell A Friend' and the title of the email that the recipient received is 'Your friend (name) has recommended this great product from (shop name)' or 'Your friend (name) would like you to visit (shop name)'.

 

I hope this has helped anyone else searching the forums who has got confused by this problem! I will post any further findings about the messages being filtered as junk mail issue here too.

 

Thanks again Dynamo, you rock!

 

 

 

Alice

Posted

Oh one more thing related to the Tell A Friend form -

 

After you click 'continue' to sumbit the form, you get sent back to the original page that you were telling your friend about, with a success message at the top saying 'Your email about (product/site) has been successfully sent to Reciever.'

 

This is the message that's got a lightbulb and a green background by default.

 

I'm not very good at PHP and I was wondering where/how I should put in a <br> (presumably in the catalogue/tell_a_friend.php file) to create a gap between this successful message and the title of the $content page. It just looks horribly squashed up. The code is included in the first post, can anyone suggest where to put in a <br> or two to make this gap just below the success message?

 

Cheers!

 

 

 

Alice

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...