Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

please help, new to php and stuck with email script


AR_1986

Recommended Posts

Hi, everyone, im trying to configure my oscommerce website email but im having a nightmare doing it.for some reason my hosted streamline.net email address wont work when i use it on my site but every other email address will. The oscommerce admin is already configured to send emails but the only address it wont send to is the one i need to work ([email protected]). As a result i assumed it must be something at my hosting providers end stopping my emails from coming through to my outlook account from the website because hotmail accounts, yahoo accounts and even my virgin media account all work. I just needed to know what has to be be done to get emails on the contact us page to send to [email protected] when people click submit. I asked my host if they knew what the problem was and they said: -

 

Thank you for your query

 

To prevent spam being sent through our webservers, there are certain conditions that must be met before our SMTP servers will send the email.

1) Email must be sent to, or from, an email address hosted by Streamline.net. An email address hosted by Streamline.net is not the same as a domain name hosted by Streamline.net. If your domain's MX record points to another email provider, it will not count as being hosted by Streamline.net.

 

2) To stop misuse of your form by third parties the sendmail_from variable should be set to your Streamline.net hosted email address. While access to the php.ini file is restricted on our shared environment, you can set this variable using the ini_set() command, shown below.

 

3) A fifth parameter -f should be added to the sendmail function. This will set the name of the from email address.

 

In its basic form, a simple sendmail script will look like this:

 

ini_set("sendmail_from", " [email protected] ");

mail($email_to, $email_subject, $email_message, $headers, '[email protected]');

?>

 

Provided that you set the sendmail variable, before attempting to send the email. Specify the from address as a fifth parameter in the sendmail function, and the email is either to, or from, a Streamline.net hosted email address you should have no problems.

 

 

Example

This example will take the information from a feedback form, send it to you in an email message, then forward the customer to a "thank you for your comments" page. In this example we will use bobsdomain.co.uk as the domain name. There is a mailbox hosted with Streamline.net called [email protected].

A simple feedback form

 

First of all we need to create a feedback form that will receive the data. We will call this form feedback.html. In its most basic form, it can look like this:

 

 

Email address:

 

Name:

 

Message:

 

<br />

 

 

 

 

 

 

example feedback form

 

Not the prettiest form, but it can be tidied up, and validation can be added at a later date. This form has three fields (email address, name and message) that users can fill in. Once the user click the Submit button, it will collect the information contained within the fields, tag the information as "email, name and message", then send the information to sendmail.php.

 

The sendmail script

 

Now we have a form that sends information to a script, we need to create a script to send the email. In this example, we will name the script sendmail.php as this is the address the our form is submitting the data to. In order to send an email, we need certain information (variables), so lets set them first.

 

ini_set('sendmail_from', $email_from);

$email_to = "[email protected]";

$name =$_POST['name'];

$email_from =$_POST['email'];

$email_subject = "Feedback from website";

$comments = $_POST['message'];

$headers =

"From: $email_from .\n";

"Reply-To: $email_from .\n";

 

Now lets build the message of the email with the users name and comments.

 

$message= "Name: ". $name . "\nComments: " . $comments;

 

Finally, let's send the email. If the email is sent we will go to a thank you page, if there is an error we will display a brief message.

 

$sent = mail($email_to, $email_subject, $message, $headers, '-f .$email_from');

if ($sent)

{

header( "Location: http://www.bobsdomain.co.uk/thankyou.html" );

} else {

echo 'There has been an error sending your comments. Please try later.';

}

?>

 

example sendmailscript form

 

This script does not have any validation or error checking, so it is not recommended that you copy it directly to your website, however, it does show the basics of sending email from our webservers, and can be used as a framework for your own scripts.

 

 

The only problem is i have no idea what that means, how to make a script, what to call it and where to put it for it to work. Im confused because the oscommerce store template comes with all its own files, like contact_us.php etc. would i have to change that? Is the script example above for people making their own site using php of would it still apply even if its a template im trying to customise. If anyone can help me, i'd be eternally grateful. Im a complete noob at php. The whole oscommerce store works apart from the email. Thankyou.

Link to comment
Share on other sites

Hi, everyone, im trying to configure my oscommerce website email but im having a nightmare doing it.for some reason my hosted streamline.net email address wont work when i use it on my site but every other email address will. The oscommerce admin is already configured to send emails but the only address it wont send to is the one i need to work ([email protected]). As a result i assumed it must be something at my hosting providers end stopping my emails from coming through to my outlook account from the website because hotmail accounts, yahoo accounts and even my virgin media account all work. I just needed to know what has to be be done to get emails on the contact us page to send to [email protected] when people click submit. I asked my host if they knew what the problem was and they said: -

 

Thank you for your query

 

To prevent spam being sent through our webservers, there are certain conditions that must be met before our SMTP servers will send the email.

1) Email must be sent to, or from, an email address hosted by Streamline.net. An email address hosted by Streamline.net is not the same as a domain name hosted by Streamline.net. If your domain's MX record points to another email provider, it will not count as being hosted by Streamline.net.

 

2) To stop misuse of your form by third parties the sendmail_from variable should be set to your Streamline.net hosted email address. While access to the php.ini file is restricted on our shared environment, you can set this variable using the ini_set() command, shown below.

 

3) A fifth parameter -f should be added to the sendmail function. This will set the name of the from email address.

 

In its basic form, a simple sendmail script will look like this:

 

ini_set("sendmail_from", " [email protected] ");

mail($email_to, $email_subject, $email_message, $headers, '[email protected]');

?>

 

Provided that you set the sendmail variable, before attempting to send the email. Specify the from address as a fifth parameter in the sendmail function, and the email is either to, or from, a Streamline.net hosted email address you should have no problems.

 

 

Example

This example will take the information from a feedback form, send it to you in an email message, then forward the customer to a "thank you for your comments" page. In this example we will use bobsdomain.co.uk as the domain name. There is a mailbox hosted with Streamline.net called [email protected].

A simple feedback form

 

First of all we need to create a feedback form that will receive the data. We will call this form feedback.html. In its most basic form, it can look like this:

 

 

Email address:

 

Name:

 

Message:

 

<br />

 

 

 

 

 

 

example feedback form

 

Not the prettiest form, but it can be tidied up, and validation can be added at a later date. This form has three fields (email address, name and message) that users can fill in. Once the user click the Submit button, it will collect the information contained within the fields, tag the information as "email, name and message", then send the information to sendmail.php.

 

The sendmail script

 

Now we have a form that sends information to a script, we need to create a script to send the email. In this example, we will name the script sendmail.php as this is the address the our form is submitting the data to. In order to send an email, we need certain information (variables), so lets set them first.

 

ini_set('sendmail_from', $email_from);

$email_to = "[email protected]";

$name =$_POST['name'];

$email_from =$_POST['email'];

$email_subject = "Feedback from website";

$comments = $_POST['message'];

$headers =

"From: $email_from .\n";

"Reply-To: $email_from .\n";

 

Now lets build the message of the email with the users name and comments.

 

$message= "Name: ". $name . "\nComments: " . $comments;

 

Finally, let's send the email. If the email is sent we will go to a thank you page, if there is an error we will display a brief message.

 

$sent = mail($email_to, $email_subject, $message, $headers, '-f .$email_from');

if ($sent)

{

header( "Location: http://www.bobsdomain.co.uk/thankyou.html" );

} else {

echo 'There has been an error sending your comments. Please try later.';

}

?>

 

example sendmailscript form

 

This script does not have any validation or error checking, so it is not recommended that you copy it directly to your website, however, it does show the basics of sending email from our webservers, and can be used as a framework for your own scripts.

 

 

The only problem is i have no idea what that means, how to make a script, what to call it and where to put it for it to work. Im confused because the oscommerce store template comes with all its own files, like contact_us.php etc. would i have to change that? Is the script example above for people making their own site using php of would it still apply even if its a template im trying to customise. If anyone can help me, i'd be eternally grateful. Im a complete noob at php. The whole oscommerce store works apart from the email. Thankyou.

 

can no one help? Im really stuck. :(

Link to comment
Share on other sites

With what mails do you have the problem?

 

Is it the contact us form, the email for a new order or an order update, or the emails send via the admin panel?

 

It seems to be all of the them, when i bought my domain i set up a couple email mailboxes, in particular ([email protected]) but they dont work with my site. I know the contact us works on the site because if i login into the oscommerce admin panel and choose a hotmail address as the Email address and Email from address it works, you can submit a contact us form and it will send straight to the hotmail address i have specified. As soon as i set the address to one of my webhost addresses ([email protected]) and try to send a contact us form, its says sent but nothing ever happens, no emails ever come to that address when i check them in outlook. So i contacted my hosting provider and the above is what they said, the only problem is im soo confused about how to translate what they said and get it working. The contact form already works, in fact the site works perfect, how would i apply the information they have given me to the oscommerce files? what files would i change and what would i need to change to get my [email protected] working? the info above mentions all sorts of things about creating sendmail.php etc but theres no such thing in the oscommerce catalog, i have no idea where i would create one, where to put it and if i even need to.

 

thankyou soo much for helping, its really testing me!

Link to comment
Share on other sites

No panic, lets take it step by step.

 

1. Go and register as a customer with an alternative (not your hosts) mail and place an order. Check following:

1.1 If you receive as a customer the 2 mails (new customer and new order)

1.2 If you receive the new order mail as a store owner

 

2. Go to admin and update your order status. Check if you receive the order status mail as a customer

 

3 Go to admin and send a mail to you-customer. Check if you receive it

 

4 For the "contact us" mail, you need to be the sender of the mail your self. Then you will receive it. You need to include the customers mail into the body of the mail.

 

4.1 Find the file catalog/contact_us.php

 

4.2 Make following changes. find the lines and compare with what you have. Back up first

 

 $error = false;
 if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'send')) {
$name = tep_db_prepare_input($HTTP_POST_VARS['name']);
$email_address = tep_db_prepare_input($HTTP_POST_VARS['email']);
$enquiry = tep_db_prepare_input($HTTP_POST_VARS['enquiry']);
// BOF multimixer//
//define variable $email_body//
$email_body = $enquiry . "\r\n" . $name . "\r\n" . $email_address;
//define variable $from_email. Set to Store owner email address as defined in Admin panel//
$from_email = (STORE_OWNER_EMAIL_ADDRESS);

// $enquiry replaced by $email_body Includes $email_body to message instead of $enquiry//
//$email_address replaced by $from_email Email is getting send from $from-email instead of $email_address//
if (tep_validate_email($email_address)) {
  tep_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, EMAIL_SUBJECT, $email_body, $name, $from_email);
  //EOF multimixer//

 

To solve issues with the other mails make the tests first

Link to comment
Share on other sites

No panic, lets take it step by step.

 

1. Go and register as a customer with an alternative (not your hosts) mail and place an order. Check following:

1.1 If you receive as a customer the 2 mails (new customer and new order)

1.2 If you receive the new order mail as a store owner

 

2. Go to admin and update your order status. Check if you receive the order status mail as a customer

 

3 Go to admin and send a mail to you-customer. Check if you receive it

 

4 For the "contact us" mail, you need to be the sender of the mail your self. Then you will receive it. You need to include the customers mail into the body of the mail.

 

4.1 Find the file catalog/contact_us.php

 

4.2 Make following changes. find the lines and compare with what you have. Back up first

 

 $error = false;
 if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'send')) {
$name = tep_db_prepare_input($HTTP_POST_VARS['name']);
$email_address = tep_db_prepare_input($HTTP_POST_VARS['email']);
$enquiry = tep_db_prepare_input($HTTP_POST_VARS['enquiry']);
// BOF multimixer//
//define variable $email_body//
$email_body = $enquiry . "\r\n" . $name . "\r\n" . $email_address;
//define variable $from_email. Set to Store owner email address as defined in Admin panel//
$from_email = (STORE_OWNER_EMAIL_ADDRESS);

// $enquiry replaced by $email_body Includes $email_body to message instead of $enquiry//
//$email_address replaced by $from_email Email is getting send from $from-email instead of $email_address//
if (tep_validate_email($email_address)) {
  tep_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, EMAIL_SUBJECT, $email_body, $name, $from_email);
  //EOF multimixer//

 

To solve issues with the other mails make the tests first

 

 

Hi George, thankyou soo much for your help. I've found the contact_us.php and openned it but i cant see certain code. This is what i have: -

 

<?php

/*

$Id: contact_us.php 1739 2007-12-20 00:52:16Z hpdl $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

*/

 

require('includes/application_top.php');

 

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

 

$error = false;

if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'send')) {

$name = tep_db_prepare_input($HTTP_POST_VARS['name']);

$email_address = tep_db_prepare_input($HTTP_POST_VARS['email']);

$enquiry = tep_db_prepare_input($HTTP_POST_VARS['enquiry']);

 

if (tep_validate_email($email_address)) {

tep_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, EMAIL_SUBJECT, $enquiry, $name, $email_address);

 

tep_redirect(tep_href_link(FILENAME_CONTACT_US, 'action=success'));

} else {

$error = true;

 

$messageStack->add('contact', ENTRY_EMAIL_ADDRESS_CHECK_ERROR);

}

}

 

$breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_CONTACT_US));

?>

<!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">

<script type="text/javascript" src="iepngfix_tilebg.js"></script>

<style type="text/css">

.ie6_png {behavior: url("iepngfix.htc") }

.ie6_png img {behavior: url("iepngfix.htc") }

.ie6_png input {behavior: url("iepngfix.htc") }

</style>

<!--[if IE]>

<script type="text/javascript" src="ie_png.js"></script>

<script type="text/javascript">

ie_png.fix('.png');

</script>

<![endif]-->

</head>

 

<body>

<!-- header //-->

<?php $tab_sel = 7; ?>

<?php require(DIR_WS_INCLUDES . 'header.php'); ?>

<!-- header_eof //-->

 

<!-- body //-->

<table border="0" class="<?php echo MAIN_TABLE; ?>" cellspacing="0" cellpadding="0">

<tr>

<td class="<?php echo BOX_WIDTH_TD_LEFT; ?>"><table border="0" class="<?php echo BOX_WIDTH_LEFT; ?>" cellspacing="0" cellpadding="0">

<!-- left_navigation //-->

<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>

<!-- left_navigation_eof //-->

</table></td>

<!-- body_text //-->

<td class="<?php echo CONTENT_WIDTH_TD; ?>"><?php echo panel_top(); ?><?php echo tep_draw_form('contact_us', tep_href_link(FILENAME_CONTACT_US, 'action=send')); ?>

 

<?php echo tep_draw_top();?>

 

<?php echo tep_draw_title_top();?>

 

<?php echo HEADING_TITLE; ?>

 

<?php echo tep_draw_title_bottom();?>

 

<?php echo tep_draw1_top();?>

 

<?php

if ($messageStack->size('contact') > 0) {

?>

<table cellpadding="0" cellspacing="0" border="0">

<tr><td><?php echo $messageStack->output('contact'); ?></td></tr>

</table>

 

<?php echo tep_pixel_trans();?>

 

<?php

}

 

if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'success')) {

?>

<table cellpadding="0" cellspacing="0" border="0">

<tr>

<td class="main" align="center"><?php echo tep_image(DIR_WS_IMAGES . 'table_background_man_on_board.gif', HEADING_TITLE, '0', '0', 'align="left"') . TEXT_SUCCESS; ?></td>

</tr>

</table>

 

<?php echo tep_pixel_trans();?>

 

<?php /* echo tep_draw_infoBox2_top(); */?>

 

<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 align="right"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE) . '</a>'; ?></td>

<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>

</tr>

</table>

 

<?php /* echo tep_draw_infoBox2_bottom(); */?>

 

<?php

} else {

?>

 

<?php /* echo tep_draw_infoBox_top(); */?>

 

<table border="0" width="100%" cellspacing="5" cellpadding="0" class="infoBox2_">

<tr>

<td class="main"><?php echo ENTRY_NAME; ?></td>

<td class="main" style="width:100%;"><?php echo tep_draw_input_field('name'); ?></td>

</tr>

<tr>

<td class="main" style="white-space:nowrap;"><?php echo ENTRY_EMAIL; ?></td>

<td class="main"><?php echo tep_draw_input_field('email'); ?></td>

</tr>

<tr>

<td class="main"><?php echo ENTRY_ENQUIRY; ?></td>

<td><?php echo tep_draw_textarea_field('enquiry', 'soft', 50, 15); ?></td>

</tr>

</table>

 

<?php /* echo tep_draw_infoBox_bottom(); */?>

 

<?php echo tep_pixel_trans();?>

 

<?php echo tep_draw_infoBox2_top();?>

 

<table border="0" width="100%" cellspacing="0" cellpadding="2">

<tr><td align="right"><?php echo tep_image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE); ?></td></tr>

</table>

 

<?php echo tep_draw_infoBox2_bottom();?>

 

<?php

}

?>

 

<?php echo tep_draw1_bottom();?>

 

<?php echo tep_draw_bottom();?>

 

</form></td>

<!-- body_text_eof //-->

<td class="<?php echo BOX_WIDTH_TD_RIGHT; ?>"><table border="0" class="<?php echo BOX_WIDTH_RIGHT; ?>" cellspacing="0" cellpadding="0">

<!-- 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 //-->

</body>

</html>

<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

Link to comment
Share on other sites

Replace this (it's near the top of the file at about lines 22-24)

 

if (tep_validate_email($email_address)) {
  tep_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, EMAIL_SUBJECT, $enquiry, $name, $email_address);

 

with this

 

// BOF multimixer//
//define variable $email_body//
$email_body = $enquiry . "\r\n" . $name . "\r\n" . $email_address;
// if you want to add more fields do so by adding this line [ ."\r\n" . ] between the fields you wish to display and order them acourdingly//
//define variable $from_email. Set to Store owner email address as defined in Admin panel//
$from_email = (STORE_OWNER_EMAIL_ADDRESS);
//EOF multimixer //

//BOF Multimixer//
// $enquiry replaced by $email_body Includes $email_body to message instead of $enquiry//
//$email_address replaced by $from_email Email is getting send from $from-email instead of $email_address//
if (tep_validate_email($email_address)) {
  tep_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, EMAIL_SUBJECT, $email_body, $name, $from_email);
  //EOF multimixer//

 

Back up your file first please. Tell me if it works

Link to comment
Share on other sites

Replace this (it's near the top of the file at about lines 22-24)

 

if (tep_validate_email($email_address)) {
  tep_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, EMAIL_SUBJECT, $enquiry, $name, $email_address);

 

with this

 

// BOF multimixer//
//define variable $email_body//
$email_body = $enquiry . "\r\n" . $name . "\r\n" . $email_address;
// if you want to add more fields do so by adding this line [ ."\r\n" . ] between the fields you wish to display and order them acourdingly//
//define variable $from_email. Set to Store owner email address as defined in Admin panel//
$from_email = (STORE_OWNER_EMAIL_ADDRESS);
//EOF multimixer //

//BOF Multimixer//
// $enquiry replaced by $email_body Includes $email_body to message instead of $enquiry//
//$email_address replaced by $from_email Email is getting send from $from-email instead of $email_address//
if (tep_validate_email($email_address)) {
  tep_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, EMAIL_SUBJECT, $email_body, $name, $from_email);
  //EOF multimixer//

 

Back up your file first please. Tell me if it works

 

I adjusted the code to this: -

 

<?php

/*

$Id: contact_us.php 1739 2007-12-20 00:52:16Z hpdl $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

*/

 

require('includes/application_top.php');

 

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

 

$error = false;

if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'send')) {

$name = tep_db_prepare_input($HTTP_POST_VARS['name']);

$email_address = tep_db_prepare_input($HTTP_POST_VARS['email']);

$enquiry = tep_db_prepare_input($HTTP_POST_VARS['enquiry']);

// BOF multimixer//

//define variable $email_body//

$email_body = $enquiry . "\r\n" . $name . "\r\n" . $email_address;

// if you want to add more fields do so by adding this line [ ."\r\n" . ] between the fields you wish to display and order them acourdingly//

//define variable $from_email. Set to Store owner email address as defined in Admin panel//

$from_email = (STORE_OWNER_EMAIL_ADDRESS);

//EOF multimixer //

 

//BOF Multimixer//

// $enquiry replaced by $email_body Includes $email_body to message instead of $enquiry//

//$email_address replaced by $from_email Email is getting send from $from-email instead of $email_address//

if (tep_validate_email($email_address)) {

tep_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, EMAIL_SUBJECT, $email_body, $name, $from_email);

//EOF multimixer//

 

tep_redirect(tep_href_link(FILENAME_CONTACT_US, 'action=success'));

} else {

$error = true;

 

$messageStack->add('contact', ENTRY_EMAIL_ADDRESS_CHECK_ERROR);

}

 

but unfortunately no emails have been sent yet. I also purchased an item from my store as you suggested and left my hotmail email address and everything went very smothly, i recieved two emails one saying'thankyou for registering' and the other was the 'order process email' so it seems the only problem is with this contact us section.

 

Another thing i have just noticed is when i replaced the original contact_us.php with the code the contact us page on the website isn't working properly, the background has turned white and all the pictures are missing, i can stills ee links and the contact us form(i can even fill the form out still) but the page doesnt load correctly. hmmm

Link to comment
Share on other sites

This changes I told you have nothing to do with your sites color. Are you sure you didn't made any other changes at the same time? Are you sure you replaced just what I told you leaving all other code untuched?

Link to comment
Share on other sites

This changes I told you have nothing to do with your sites color. Are you sure you didn't made any other changes at the same time? Are you sure you replaced just what I told you leaving all other code untuched?

 

Sorry, that was my mistake, i must have made a mistake when i was entering the code, the page looks fine now. just trying the form now.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...