Jump to content

Recommended Posts

Posted

How can I add a "from" address when using the PHP "mail" function to send an e-mail.

 

I have the following code:

 

><?php
   $msg = "This is the message of the e-mail";
   if (mail ('you@mail.com', 'This is the Subject', $msg, null, '-fme@mail.com')) {
       echo "Mail was successfully sent\n";
   } else {
       echo "Cannot send mail\n";
   }
?>

 

The e-mail is sent, but it has a "from" address of Nobody@@server63.totalchoicehosting.com

 

Thanks for the help!

Posted

I tend to use full headers on the email, which includes the from and reply-to variables as shown here;

 

 

>$myname = "My full name"; 
$myemail = "myname@myaccount.com"; 

$contactname = "their name"; 
$contactemail = "their.name@theiraccount.com"; 

$subject = "This is the subject"; 

$message .= "Test message\n"; 
$message .= "\n"; 
$message .= "signature\n"; 

$headers .= "From: $myname <$myemail>\r\n"; 
$headers .= "Reply-To: $myname <$myemail>\r\n"; 
$headers .= "To: $contactname <$contactemail>\r\n"; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
$headers .= "X-Priority: 1\r\n"; 
$headers .= "X-MSMail-Priority: High\r\n"; 
$headers .= "X-Mailer: My PHP Mailer\n";

mail($contactemail, $subject, $message, $headers, "-f".$myemail);

Posted

Or put simply and using less code

>mail(wheretosendemail, emailssubject, emailsmessage, headers)

 

In the headers put From: "YOUR NAME" <youremailaddress>

 

You don't have to put your name in quotes I just do it out of habit.

 

eg

>mail('nobody@here.com', 'Just Hello', 'Just an email to say hello', 'From: "carbonize" <webmaster@carbonize.co.uk>');

Posted

If you use the shortened method, and then look at the headers, you will see that the "Return-path: "

 

This is not the case with the full version, although I admit you could miss out a lot of it :lol:

  • 4 weeks later...
Posted (edited)

I used your headers, but the mails still end up with nobody in return path... what do you think is wrong?

 

 

$headers = "From: xxx<$email_mailingupdate2>\r\n";

$headers .= "Reply-To: xxx<$email_mailingupdate2>\r\n";

$headers .= "Return-Path: xxx<$email_mailingupdate2>\n";

$headers .= "MIME-Version: 1.0\r\n";

$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";

$headers .= "X-Priority: 1\r\n";

$headers .= "X-MSMail-Priority: High\r\n";

$headers .= "X-Mailer: My PHP Mailer\n";

$headers .= "To: $val <$val>\r\n";

$result=mail($val, $subject,$message,$headers);

 

here is the result:

 

 

X-Apparently-To: xxx@yahoo.com via 206.190.36.196; Sun, 14 Aug 2005 21:29:40 -0700

X-Originating-IP: [69.50.218.37]

Return-Path: <nobody@dedicated115.snhdns.com>

Authentication-Results: mta142.mail.mud.yahoo.com from=xxx.com; domainkeys=neutral (no sig)

Received: from 69.50.218.37 (EHLO dedicated115.snhdns.com) (69.50.218.37) by mta142.mail.mud.yahoo.com with SMTP; Sun, 14 Aug 2005 21:29:40 -0700

Received: from nobody by dedicated115.snhdns.com with local (Exim 4.50) id 1E4WbS-00026l-Td for xxx@yahoo.com; Mon, 15 Aug 2005 05:29:38 +0100

To: xxx@yahoo.com

Subject: test5

From: "xxx" <breakingnews@xxx.com> Add to Address Book

Reply-to: xxx<breakingnews@xxx.com>

MIME-Version: 1.0

Content-type: text/plain; charset=iso-8859-1

X-Priority: 1

X-MSMail-Priority: High

X-Mailer: My PHP Mailer

To: xxx@yahoo.com,

Message-Id: <E1E4WbS-00026l-Td@dedicated115.snhdns.com>

Date: Mon, 15 Aug 2005 05:29:38 +0100

X-AntiAbuse: This header was added to track abuse, please include it with any abuse report

X-AntiAbuse: Primary Hostname - dedicated115.snhdns.com

X-AntiAbuse: Original Domain - yahoo.com

X-AntiAbuse: Originator/Caller UID/GID - [99 99] / [47 12]

X-AntiAbuse: Sender Address Domain - dedicated115.snhdns.com

X-Source:

X-Source-Args:

X-Source-Dir:

Content-Length: 6

Edited by soned
Posted

-fmyname@myaccount.com should be -fyouremailaddress@yourtchdomain.com if I read that right. So for me it would be -frob@mytchdomain.com.

 

Please remember that the helpdesk is not there to answer questions about how to perform certain scripting functions. They are there for server related issues.

Posted

thanks, guys. that helped somewhat but we still have some users who dont get the emails. here's a sample header from them:

 

 

Return-path: <xx@xxxx.com>

Received: from nobody by dedicated115.snhdns.com with local (Exim 4.50)

id 1E5LSh-0005gs-6P

for xx.xx@xx.xx.com; Wed, 17 Aug 2005 11:47:59 +0100

 

there's still a nobody showing up. Before, the problem was with the return-path having nobody. The thing with -fname@host.com fixed that one.

 

 

here's anothor mentioning about our ip:

 

tim.xx@xxx.com

SMTP error from remote mailer after RCPT TO:<tim.xx@xxx.com>:

host gnateater.rjf.com [170.12.128.132]: 550 5.7.1 <tim.xx@xxx.com>... Relaying denied. IP name lookup failed [69.50.218.37]

 

 

 

SMTP error from remote mailer after RCPT TO:<lisa.xx@xxx.co.uk>:

host xx.co.uk [212.67.202.80]: 550 relaying to <lisa.xx@xx.co.uk> prohibited by administrator (failed to find host name from IP address)

 

 

 

 

 

so we have a problem with the recipient verifying my server's ip address.

 

any thoughts?

Posted

I'm fairly sure that the problem is the rDNS is not set up on your server. If you open a ticket at the help desk, provide us with the full header for that (so we can check) and ask us to check the rDNS is set up correctly we'll look into it for you.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...