Jump to content


Photo

mail() help


  • Please log in to reply
5 replies to this topic

#1 Janus13

Janus13
  • Members
  • PipPipPip
  • Advanced Member
  • 54 posts

Posted 02 March 2006 - 01:56 AM

I am seeing some odd behavior out of the mail function. I run a member management package on Apache with mysql and php 4. When the mail functions get invoked sometimes exim mail servers will reject the mail because it appears to originate from nobody@server. Is there a way to specify a user for the mail function to send from so they don't get rejected?

#2 Hooker

Hooker
  • Members
  • PipPipPip
  • Advanced Member
  • 193 posts
  • LocationWales, UK

Posted 02 March 2006 - 06:29 AM

Try something like this:

      $email = "whoever@yourmailing.com";
      $subject = "Subject!";
      $body = "whatever you want to email";
      $from = "From: Emailers Name <email@address.com>";
 mail($email,$subject,$body,$from);

it should do exactly what you need, you can always put the details directly into the mail() function but i prefer to have them in variables outside of the function.

#3 Janus13

Janus13
  • Members
  • PipPipPip
  • Advanced Member
  • 54 posts

Posted 04 March 2006 - 08:12 AM

But does "nobody" still originate the email? I'll give this a try and see if it makes any difference.

#4 Hooker

Hooker
  • Members
  • PipPipPip
  • Advanced Member
  • 193 posts
  • LocationWales, UK

Posted 04 March 2006 - 05:18 PM

Heres the difference:

      $from = "From: Emailers Name <email@address.com>";

The mail will be listed as from "Emailers Name" and also have the return address of "email@address.com" some spam filters may look at the header info of the email but it should work fine for most.

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 04 March 2006 - 08:51 PM

You probably need to use the fifth parameter to the mail() function to change the "Return-path:" header to include the domainname you're sending from.

<?php
$p5 = '-f somename@yourdomainname.com';
mail($to,$subj,$mesg,$from,$p5);
?>

Ken

#6 Janus13

Janus13
  • Members
  • PipPipPip
  • Advanced Member
  • 54 posts

Posted 05 March 2006 - 02:47 AM

So this should work ok?

function mymail($to,$subject,$message,$from){

$option = "-f me@mydomain.com";
mail($to,$subject,$message,$from,$option);
}

$to = "someone@someone.com";
$subject = "Test Email";
$message = "This is a test message";
$from = "From: My Site <me@mydomain.com>";
mymail($to,$subject,$message,$from);

Also, the earlier suggestion doesn't seem to make any difference, so I'm hoping the last option will work.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users