View Full Version : Send From Email showing accountname@boxXXX.bluehost.com
nathhill
12-21-2006, 09:44 AM
Hi, I have downloaded a Tell-a-Friend page in my site using cgi script. When I tested it, it sent an email to the friend with my own email that shows my accountname@boxXXX.bluehost.com. How do I correct this?
Also, I downloaded the files accompanying it. One of them is config.txt that has the following code:
template_top_location=c:/windows/desktop/expertwebinstalls/cgi-bin/templates/top.html
template_bottom_location=c:/windows/desktop/expertwebinstalls/cgi-bin/templates/bottom.html
sendmail_path=/usr/sbin/sendmail
I am confused about the /usr/sbin/sendmail as I do not see that in any of my directories....any help for this newbie is appreciated.
areidmtm
12-21-2006, 09:53 AM
Make sure you have the from header
<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
Also the sendmail is a server thing, just keep it like that
nathhill
12-21-2006, 10:38 AM
Thanks. I am using cgi...can I use the same code?
areidmtm
12-21-2006, 10:40 AM
oh sorry, didn't read that you're using CGI. No you cannot use that same code. Just make sure in your CGI code that your using the From header.
If you need help with that, post your code here any we'll be able to help.
nathhill
12-21-2006, 10:40 AM
Here is the code for the Emailer.pm I use:
package Freedom::Emailer;
#use Net::SMTP;
use Freedom::Config;
sub new {
#my $proto = shift;
#my $class = ref($proto) || $proto;
my $config_path = $_[1];
my $config = Freedom::Config->new($config_path);
my $self = {sendmail_path=>$config->one('sendmail_path')};
bless ($self, $class);
return bless $self;
}
sub send {
my $self = shift;
# read all needed variables from input passed to this object method as an anonymous hash
my %input_hash = @_;
my $sender_email = $input_hash{'from_email'};
my $sender_name = $input_hash{'from_name'};
my $email_address = $input_hash{'to_email'};
my $email_name = $input_hash{'to_name'};
my $email_subject = $input_hash{'subject'};
my $email_body = $input_hash{'message'};
my $use_sockets = $input_hash{'use_sockets'};
my $email_server = $input_hash{'email_server'};
# format the date in the first format, not the localtime format (second)
# Sat, 21 Jul 2001 16:31:34 -0700 (PDT)
# Sat Jul 21 16:33:10 2001
# Define arrays for the day of the week and month of the year. #
my @days = ('Sun','Mon','Tue','Wed',
'Thu','Fri','Sat');
my @months = ('Jan','Feb','Mar','Apr','May','Jun','Jul',
'Aug','Sep','Oct','Nov','Dec');
# Get the current time and format the hour, minutes and seconds. Add #
# 1900 to the year to get the full 4 digit year. #
my ($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6];
my $time = sprintf("%02d:%02d:%02d",$hour,$min,$sec);
$year += 1900;
# format for the -0700 thingy
my $over_10;
my $first;
my $second;
my $minus_24 = $hour - 24;
$minus_24++;
my $tester = $minus_24;
$tester =~ s/-|0//g;
if ($tester > 9) {
$over_10 = 1;
}
# if the number is over 10, I have to parse it differently
if ($over_10) {
my $useless;
my $remainder;
$minus_24 .= "00";
if ($minus_24 =~ /-/) {
($useless, $remainder) = split (/-/, $minus_24);
# remainder is now "700" or the like
my $next_minus_24 = "-" . $remainder;
$minus_24 = $next_minus_24;
}
# print $minus_24;
} else {
# then it's under 10
my $useless;
my $remainder;
$minus_24 .= "00";
if ($minus_24 =~ /-/) {
($useless, $remainder) = split (/-/, $minus_24);
# remainder is now "700" or the like
my $next_minus_24 = "-0" . $remainder;
$minus_24 = $next_minus_24;
} else {
# then it's a positive number under 10
my $next_minus_24 = "0" . $remainder;
$minus_24 = $next_minus_24;
}
}
# Format the date. #
my $date = "$days[$wday], $mday $months[$mon] $year $time $minus_24 (PDT)";
my $message = <<EOF;
Date: $date
From: "Accessible Travel Guides"
Subject: $email_subject
To: $email_address ($email_name)
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 7bit
$email_body
EOF
#if ($use_sockets) {
# do the non-sendmail (sockets/smtp) way of sending email:
# more security - use if possible!
# my $smtp = Net::SMTP->new($email_server, Debug=>1);
# $smtp->mail($email_address);
# $smtp->to($email_address);
# $smtp->data();
# $smtp->datasend($message);
# $smtp->dataend();
# $smtp->quit;
#} else {
# if this were unix or we installed sendmail on Win*, we could use this code:
# some crappy web hosting services don't let you specify 'oi' to sendmail...
# open (PIPE_TO_SENDMAIL, "| $sendmail_path -t oi") || die ("could not open pipe to sendmail at $sendmail_path because $!");
#use CGI qw(:standard);
#print header, $self->{'sendmail_path'};
#exit;
open (PIPE_TO_SENDMAIL, "| $self->{'sendmail_path'} $email_address") || die ("could not open pipe to sendmail at $sendmail_path because $!");
print PIPE_TO_SENDMAIL $message;
close(PIPE_TO_SENDMAIL);
#use CGI qw(:standard);
#print header, $message;
#exit;
#}
}
1;
areidmtm
12-21-2006, 10:41 AM
From: "Accessible Travel Guides"
This part of your code, try using an email address instead of a name
nathhill
12-21-2006, 11:05 AM
Tried using that instead, tried all types of combination including:
From: "info\@accessibletravelguides.com"(AccessibleTravelGuides)
From: 'info@accessibletravelguides.com"
From: "Accessible Travel Guides"
...the email address with the bluehost domain still shows up.
Here is the actual cgi file:
#!/usr/bin/perl -w
# Copyright David Nelson & Expert Web Installs
# Free software, licensed under the GPL ( http://www.gnu.org/licenses/gpl.txt )
# Visit http://www.expertwebinstalls.com/r/easy_tell_a_friend.html for installation help
use strict;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);
my $sf = $ENV{'SCRIPT_FILENAME'};
my $r_sf = reverse $sf;
my ($script_name, @wanted_path_reverse) = split(/\//, $r_sf);
my $wanted_path_reverse = join('/', @wanted_path_reverse);
my $wanted_path = reverse $wanted_path_reverse;
$wanted_path = '/' . $wanted_path;
unless ($wanted_path =~ /:/) # windows machines
{
$wanted_path = '/' . $wanted_path;
}
use lib qw($wanted_path);
my $config_path = $wanted_path . '/config.txt';
use Freedom::Emailer;
use Freedom::Config;
use Freedom::Validate;
use Freedom::Display;
my $config = Freedom::Config->new($config_path);
my $emailer = Freedom::Emailer->new($config_path);
my $validate = Freedom::Validate->new($config_path);
my $display = Freedom::Display->new($config_path);
my $url = url;
my $mode = param('mode');
if($mode eq 'bad_email')
{
my $stored_referrer = param('stored_referrer');
print "Location: http://www.accessibletravelguides.com/Error_Refer.html\n\n";
}
elsif($mode eq 'send_email')
{
my $referrer;
my $to_name = param('friends_name');
my $to_email = param('friends_email');
my $from_name = param('your_name');
my $from_email = param('your_email');
my $specific_comments = param('specific_comments') || '';
if(param('referrer_url') ne '')
{
$referrer = param('referrer_url');
}
else
{
$referrer = $ENV{'HTTP_REFERER'};
}
unless($validate->email_address(param('your_email')) &&
$validate->email_address(param('friends_email')))
{
print redirect("$url?mode=bad_email&stored_referrer=$referrer&friends_name=$to_name&" .
"friends_email=$to_email&your_name=$from_name&your_email=$from_email&" .
"specific_comments=$specific_comments");
exit;
}
my $comments_to_send;
if($specific_comments ne '')
{
$comments_to_send .= "\n$from_name specifically wanted to mention:\n\n$specific_comments\n";
}
my $message_subject = $from_name . ' recommends you visit www.accessible-travel-guides.com';
my $message;
open(F, "$wanted_path/tell_a_friend_message.txt") || die("could not open message file at $wanted_path/message.txt because: $!");
while(<F>)
{
$message .= $_;
}
$message =~ s/%%to_name%%/$to_name/sg;
$message =~ s/%%from_name%%/$from_name/sg;
$message =~ s/%%comments_to_send%%/$comments_to_send/sg;
$emailer->send(to_name=>$to_name,
to_email=>$to_email,
from_name=>$from_name,
from_email=>$from_email,
subject=>$message_subject,
message=>$message);
print "Location: http://www.accessibletravelguides.com/Thanks_Refer.html\n\n";
}
else
{
print $display->full('Bad Mode Specified. Exiting');
}
felgall
12-21-2006, 11:17 AM
info@accessibletravelguides.com will work provided that the email address actually exists as a real mailbox, forwarder, or autoresponder.
nathhill
12-21-2006, 01:08 PM
It does exist as one of mail accounts and autoresponder. Am trying to find which code is writing that address to the friend's email header...still no idea...
Pethens
12-21-2006, 02:25 PM
This code (or the equivalent in PHP) works for me, assuming the from address is valid:
my $message = <<EOF;
Date: $date
From: "Accessible Travel Guides" <info@accessibletravelguides.com>
Subject: $email_subject
To: $email_address ($email_name)
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 7bit
$email_body
EOF
If you do it this way the from address in the receiver's email client will show the address you want. However, if they take the trouble to view headers, it will always show "boxXX.bluehost.com". There's nothing you can do about that, as far as I know.
Stephen
nathhill
12-21-2006, 06:40 PM
Thanks. I did that too...and you're right, it still showed the bluehost email address. oh well...I guess I can live with that. Cheers!
vaidy
12-29-2006, 07:19 AM
Make sure you have the from header
<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
Also the sendmail is a server thing, just keep it like that
Hi, I have an exactly similar problem. The mail options allowed in the SMF forum that I set up in a subdomain of my main accout are 'php' and 'smtp'.
smtp is not working with a gmail id that I used.
Where is the From header? I mean which file is it located in? How can I do this? Please help.
areidmtm
12-29-2006, 12:42 PM
using gmail and PHP is A LOT harder. You cannot simply put you gmail info in with SMTP becasue gmail also uses TSL and SSL.
Search Google for gmail and PHP
vaidy
12-29-2006, 08:26 PM
Does it mean that I can use web based emails like hotmail or yahoomail easily?
areidmtm
12-30-2006, 12:52 AM
Does it mean that I can use web based emails like hotmail or yahoomail easily?
if you're trying to send mail from PHP with a hotmail or yahoo account, that depends. If hotmail and yahoo allow you to use POP and smtp. I'm not sure, but Google does, if you know the way to get PHP to use SSL.
http://www.swiftmailer.org/ will work with gmail accounts
vaidy
12-30-2006, 04:00 PM
Sorry mate, I lost you there. I have no (I was about to say 'limited' :D ) coding knowledge, so much of my tweaking is after visiting forums and googling!
I have actually set right the problem:
Action:
1. I use a google aps account - help@mydomain.org, so the mx details in the cpanel point to google aps.
2. I now created a dummy help@mydomain.org email id in cpanel.
3. I changed the php.ini file as per bluehost helpdesk (http://helpdesk.bluehost.com/kb/index.php?x=&mod_id=2&id=231) directions and put a copy of the php.ini file in every demmed directory!
It worked :) !
Behaviour:
Was awake till 4:30 am today :( .
Consequence:
A very angry wife:eek:
Now, what I dont understand is:
The difference between various mails:
php() mail, sendmail, etc. I understand smtp as I use the settings in my outlook to download mails direct into my PC.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.