Php Mail

liunx

Guest
How can I add a "from" address when using the PHP "mail" function to send an e-mail.<br /><br />I have the following code:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php<br />    $msg = "This is the message of the e-mail";<br />    if (mail ('[email protected]', 'This is the Subject', $msg, null, '[email protected]')) {<br />        echo "Mail was successfully sent\n";<br />    } else {<br />        echo "Cannot send mail\n";<br />    }<br />?><!--c2--></div><!--ec2--><br /><br />The e-mail is sent, but it has a "from" address of Nobody@@server63.totalchoicehosting.com<br /><br />Thanks for the help!<!--content-->
I tend to use full headers on the email, which includes the from and reply-to variables as shown here;<br /><br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->$myname = "My full name"; <br />$myemail = "[email protected]"; <br /><br />$contactname = "their name"; <br />$contactemail = "[email protected]"; <br /><br />$subject = "This is the subject"; <br /><br />$message .= "Test message\n"; <br />$message .= "\n"; <br />$message .= "signature\n"; <br /><br />$headers .= "From: $myname <$myemail>\r\n"; <br />$headers .= "Reply-To: $myname <$myemail>\r\n"; <br />$headers .= "To: $contactname <$contactemail>\r\n"; <br />$headers .= "MIME-Version: 1.0\r\n"; <br />$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; <br />$headers .= "X-Priority: 1\r\n"; <br />$headers .= "X-MSMail-Priority: High\r\n"; <br />$headers .= "X-Mailer: My PHP Mailer\n";<br /><br />mail($contactemail, $subject, $message, $headers, "-f".$myemail);<!--c2--></div><!--ec2--><!--content-->
Or put simply and using less code<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->mail(wheretosendemail, emailssubject, emailsmessage, headers)<!--c2--></div><!--ec2--><br /><br />In the headers put <b>From: "YOUR NAME" <youremailaddress></b><br /><br />You don't have to put your name in quotes I just do it out of habit.<br /><br />eg<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->mail('[email protected]', 'Just Hello', 'Just an email to say hello', 'From: "carbonize" <[email protected]>');<!--c2--></div><!--ec2--><!--content-->
If you use the shortened method, and then look at the headers, you will see that the <b>"Return-path: <[email protected]>"</b> <br /><br />This is not the case with the full version, although I admit you could miss out a lot of it <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" /><!--content-->
return path is really only needed if you want replies to go to an address other than the from address.<!--content-->
I used your headers, but the mails still end up with nobody in return path... what do you think is wrong?<br /><br /><br /> $headers = "From: xxx<$email_mailingupdate2>\r\n";<br /> $headers .= "Reply-To: xxx<$email_mailingupdate2>\r\n";<br /> $headers .= "Return-Path: xxx<$email_mailingupdate2>\n";<br /> $headers .= "MIME-Version: 1.0\r\n"; <br /> $headers .= "Content-type: text/plain; charset=iso-8859-1\r\n"; <br /> $headers .= "X-Priority: 1\r\n"; <br /> $headers .= "X-MSMail-Priority: High\r\n"; <br /> $headers .= "X-Mailer: My PHP Mailer\n";<br /> $headers .= "To: $val <$val>\r\n"; <br /> $result=mail($val, $subject,$message,$headers);<br /><br />here is the result:<br /><br /><br />X-Apparently-To: <!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e --> via 206.190.36.196; Sun, 14 Aug 2005 21:29:40 -0700 <br />X-Originating-IP: [69.50.218.37] <br />Return-Path: <[email protected]> <br />Authentication-Results: mta142.mail.mud.yahoo.com from=xxx.com; domainkeys=neutral (no sig) <br />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 <br />Received: from nobody by dedicated115.snhdns.com with local (Exim 4.50) id 1E4WbS-00026l-Td for <!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->; Mon, 15 Aug 2005 05:29:38 +0100 <br />To: <!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e --> <br />Subject: test5 <br />From: "xxx" <[email protected]> Add to Address Book <br />Reply-to: xxx<[email protected]> <br />MIME-Version: 1.0 <br />Content-type: text/plain; charset=iso-8859-1 <br />X-Priority: 1 <br />X-MSMail-Priority: High <br />X-Mailer: My PHP Mailer <br />To: <!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->, <br />Message-Id: <[email protected]> <br />Date: Mon, 15 Aug 2005 05:29:38 +0100 <br />X-AntiAbuse: This header was added to track abuse, please include it with any abuse report <br />X-AntiAbuse: Primary Hostname - dedicated115.snhdns.com <br />X-AntiAbuse: Original Domain - yahoo.com <br />X-AntiAbuse: Originator/Caller UID/GID - [99 99] / [47 12] <br />X-AntiAbuse: Sender Address Domain - dedicated115.snhdns.com <br />X-Source: <br />X-Source-Args: <br />X-Source-Dir: <br />Content-Length: 6<!--content-->
instead of <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->$result=mail($val, $subject,$message,$headers);<!--c2--></div><!--ec2-->try<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->$result=mail($val, $subject,$message,$headers, "[email protected]");<!--c2--></div><!--ec2--><!--content-->
what's <!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e --> for my server?<br /><br />I Think I'll open a ticket for this one<!--content-->
<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e --> should be <!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e --> if I read that right. So for me it would be <!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->.<br /><br />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.<!--content-->
thanks, guys. that helped somewhat but we still have some users who dont get the emails. here's a sample header from them:<br /><br /><br />Return-path: <[email protected]><br />Received: from nobody by dedicated115.snhdns.com with local (Exim 4.50)<br /> id 1E5LSh-0005gs-6P<br /> for <!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->; Wed, 17 Aug 2005 11:47:59 +0100<br /><br />there's still a nobody showing up. Before, the problem was with the return-path having nobody. The thing with <!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e --> fixed that one.<br /><br /><br />here's anothor mentioning about our ip:<br /><br />[email protected]<br /> SMTP error from remote mailer after RCPT TO:<[email protected]>:<br /> host gnateater.rjf.com [170.12.128.132]: 550 5.7.1 <[email protected]>... Relaying denied. IP name lookup failed [69.50.218.37]<br /><br /><br /><br />SMTP error from remote mailer after RCPT TO:<[email protected]>:<br /> host xx.co.uk [212.67.202.80]: 550 relaying to <[email protected]> prohibited by administrator (failed to find host name from IP address)<br /><br /><br /><br /><br /><br />so we have a problem with the recipient verifying my server's ip address.<br /><br />any thoughts?<!--content-->
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.<!--content-->
 
Back
Top