Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Installation/Configuration

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 5th September 2006, 12:07
edge edge is offline
Moderator
 
Join Date: Dec 2005
Location: The Netherlands
Posts: 2,034
Thanks: 265
Thanked 152 Times in 132 Posts
Default Weird problem when sending email from a PHP form.

I've got this online registration for that will send a confirmation email back to the user.
The problem is that when the email is send from the form it will show "www-data@host.domainname.tld"
Problem with this is that there is no SPF record for this, causing some registrations not to get to the user (hotmail does not accept mail when SPF is wrong)

Now my HOSTNAME is host.domainname.tld, so I thought by adding host.domainname.tld to the existing SPF record for domainname.tld would fix it.
Wrong.. The problem is still their.

The problem is the from: www-data@host.domainname.tld
I think if it would read www-data@domainname.tld that all is okay!

I've had a look at PHP.ini, but see nothing where I can set this.

Anyone here who might know how to fix this problem?

This is the data from the: mail.info file
(note that I have changed some things for privacy reasons)
I have changed the domainname.tld, the email_address, an_email_address and the IP: 11.22.33.44


When sending from the PHP form:
Quote:
Sep 5 11:21:16 host postfix/pickup[11837]: DB072125000F: uid=33 from=<www-data>
Sep 5 11:21:16 host postfix/cleanup[14600]: DB072125000F: message-id=<20060905092116.DB072125000F@domainname.tld>
Sep 5 11:21:16 host postfix/qmgr[11838]: DB072125000F: from=<www-data@host.domainname.tld>, size=522, nrcpt=1 (queue active)
Sep 5 11:21:18 host postfix/smtp[14602]: DB072125000F: to=<email_address@gmail.com>, relay=gmail-smtp-in.l.google.com[72.14.205.27], delay=2, status=sent (250 2
Sep 5 11:21:18 host postfix/qmgr[11838]: DB072125000F: removed
When sending with SMTP (and all is ok!):
Quote:
Sep 5 11:24:21 host postfix/smtpd[15452]: connect from a11-22-33-44.adsl.cistron.nl[11.22.33.44]
Sep 5 11:24:21 host postfix/smtpd[15452]: 2E60B125000F: client=a11-22-33-44.adsl.cistron.nl[11.22.33.44], sasl_method=LOGIN, sasl_username=web4_me
Sep 5 11:24:21 host postfix/cleanup[15454]: 2E60B125000F: message-id=<004f01c6d0cd$46731ca0$0400000a@xeon2>
Sep 5 11:24:21 host postfix/qmgr[11838]: 2E60B125000F: from=<me@an_email_address>, size=685, nrcpt=1 (queue active)
Sep 5 11:24:21 host postfix/smtpd[15452]: disconnect from a11-22-33-44.adsl.cistron.nl[11.22.33.44]
Sep 5 11:24:22 host postfix/smtp[15455]: 2E60B125000F: to=<email_address@gmail.com>, relay=gmail-smtp-in.l.google.com[72.14.205.27], delay=1, status=sent (250 2
Sep 5 11:24:22 host postfix/qmgr[11838]: 2E60B125000F: removed

Last edited by edge; 5th September 2006 at 12:11.
Reply With Quote
Sponsored Links
  #2  
Old 5th September 2006, 12:31
sjau sjau is offline
Local Meanie
 
Join Date: Apr 2006
Location: Switzerland
Posts: 1,146
Thanks: 4
Thanked 55 Times in 51 Posts
Default

Well, you could set a sender in the PHP form.
Reply With Quote
  #3  
Old 5th September 2006, 12:40
Ben Ben is offline
Moderator
 
Join Date: Jul 2006
Posts: 1,029
Thanks: 7
Thanked 62 Times in 56 Posts
Default

Can you post the php code?

What you additianlly can do is to set the -f parameter for sendmail in the php.ini to fix set the from address, wich is a real from address and no x-from address...
Reply With Quote
  #4  
Old 5th September 2006, 13:07
edge edge is offline
Moderator
 
Join Date: Dec 2005
Location: The Netherlands
Posts: 2,034
Thanks: 265
Thanked 152 Times in 132 Posts
Default

Quote:
Originally Posted by Ben
Can you post the php code?

What you additianlly can do is to set the -f parameter for sendmail in the php.ini to fix set the from address, wich is a real from address and no x-from address...
This is part of the password recover code:

PHP Code:
if($_REQUEST['recover'])
{
    
STemplate::assign('receiver_name'$rs->fields['username']);
    
STemplate::assign('receiver_fname'$rs->fields['fname']);
    
STemplate::assign('receiver_lname'$rs->fields['lname']);
    
STemplate::assign('password'$rs->fields['pwd']);
    
    
$rs $conn->execute("select * from emailinfo where email_id='recover_password'");
    
$subj $rs->fields['email_subject'];
    
$email_path $rs->fields['email_path'];
    
$body STemplate::fetch($email_path);
    @
mailing($_REQUEST['email'], $config['site_name'], $config['admin_email'], $subj$body);
    
    
$msg "An email is sent to your email address. Plese check it now.";
    
    
header("Location: recoverpass.php?msg=$msg");

This is how the main mail function looks:
PHP Code:
//MAIL FUNCTIION
function mailing($to,$name,$from,$subj,$body,$bcc=""
{
    global 
$SERVER_NAME;
    
$subj=nl2br($subj);
    
$body=nl2br($body);
    
$recipient $to;
    if(
$bcc!=""$headers "Bcc: " $bcc."\n";
    
$headers .= "From: " $from "\n";
    
//$headers .= "X-Sender: <" . "$to" . ">\n";
    //$headers .= "Return-Path: <" . "$to" . ">\n";
    //$headers .= "Error-To: <" . "$to" . ">\n";
    
$headers .= "Content-Type: text/html\n";
    
mail("$recipient","$subj","$body","$headers");

and a small part of the signup form

PHP Code:
                    {
                            
$expired_time date("Y-m-d H:i:s"strtotime("+".$rs->fields['trial_period']." day"));
                    
                            
$sql "update subscriber set
                                    pack_id=$_REQUEST[pack_id],
                                    subscribe_time='"
.date("Y-m-d H:i:s")."',
                                    expired_time='$expired_time'
                                    where UID = $userid"
;
                            
$conn->execute($sql);
                            
                            
SESSION_REGISTER("UID");            $_SESSION[UID]=$userid;
                            
SESSION_REGISTER("EMAIL");            $_SESSION[EMAIL]="$_REQUEST[email]";
                            
SESSION_REGISTER("USERNAME");        $_SESSION[USERNAME]="$_REQUEST[username]";
                            
SESSION_REGISTER("EMAILVERIFIED");    $_SESSION[EMAILVERIFIED]="no";
                            
####################### Email                
                            
$ran=time().rand(1,99999999);
                            
$sql="update verify as v, signup as s set
                                            v.vcode='$ran',
                                            s.emailverified='no' WHERE v.UID=s.UID and v.UID='$userid'"
;
                            
$conn->execute($sql);
                            
STemplate::assign('vcode',$ran);

                            
$to=$_SESSION[EMAIL];
                            
$name=$config['site_name'];
                            
$from=$config['admin_email'];
                            
$rs $conn->execute("select * from emailinfo where email_id='verify_email'");
                            
$subj $rs->fields['email_subject'];
                            
$email_path $rs->fields['email_path'];
                            
                            
$mailbody=STemplate::fetch($email_path);
                            
mailing($to,$name,$from,$subj,$mailbody);
                            
$msg "A verification email is sent to your address. Please check your email.";
                            
##################### end Email SECTION 

                            
if($_REQUEST['next']!="")$page=$_REQUEST['next'].".php";else $page="invite_signup.php";
                            if(
$_REQUEST['add']!="")$add=base64_decode($add);
                                    
header("Location:$config[baseurl]/$page?$add");exit;
                    } 
Not sure if this is all what is needed to fix the problem (it's not my code)

Last edited by edge; 5th September 2006 at 13:14.
Reply With Quote
  #5  
Old 5th September 2006, 14:15
Ben Ben is offline
Moderator
 
Join Date: Jul 2006
Posts: 1,029
Thanks: 7
Thanked 62 Times in 56 Posts
Default

Well I splitted my lines of the header with \r\n instead of only \n but I'm note sure if there was a change or not...

So my header var looks e.g. sth like this, if I don't use Pear's Mail class.
PHP Code:
$header "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html; charset=iso-8859-1\r\n";
$header .= "From: emai@domain.tld <emai@domain.tld>\r\n"
Reply With Quote
  #6  
Old 5th September 2006, 16:57
edge edge is offline
Moderator
 
Join Date: Dec 2005
Location: The Netherlands
Posts: 2,034
Thanks: 265
Thanked 152 Times in 132 Posts
 
Default

Thanks for the input, but I found the problem!

In the mail function I had to replace: mail("$recipient","$subj","$body","$headers"); with mail("$recipient","$subj","$body","$headers","-f$from");

(note the -f and $from)

All is working fine now..
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie: Creating a simple php form email, how? mancho Programming/Scripts 3 8th August 2006 16:07
Problem with 'CC' & 'BCC' email not being delivered. snowfly HOWTO-Related Questions 10 20th July 2006 12:36
php script injections Grizzly General 21 18th July 2006 08:55
Downgrade php5 to php4.4.2 llizards Installation/Configuration 4 13th March 2006 23:58
Sending email problem andrew2603 Installation/Configuration 4 7th February 2006 03:36


All times are GMT +2. The time now is 08:27.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.