Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Email from with PHP object?

Posted on 2003-11-13
4
Medium Priority
?
315 Views
Last Modified: 2006-11-17
I am preparing to use PHP mail to send and email to an automated system.  My problem is that I need to be able to change the from email address with every message I send.  Now, it automatically defaults to the address for the server that sent the mail.

It currently sends like this;

mail( "to:", "subject:", "message:", "email header:" );

I need it to send like this;

mail( "to:", "subject:", "message:", "from:" );

Is there a way to do this with PHP?  Do I have to use a different email object or something?

Thanks!
0
Comment
Question by:flatery
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
DoppyNL earned 1000 total points
ID: 9739446
You can do it like this:


$headers = 'From: "sendername" <senderemail@adress.com>'."\n"
mail('to@adress.com', 'subject', 'message body', $headers);


you can also add a bounce address:
$headers .= 'Return-Path: <bounce@address.com'."\n"
0
 

Author Comment

by:flatery
ID: 9739483
Perfect, Thanks!!
0
 
LVL 1

Expert Comment

by:vincevincevince
ID: 9742563
the from information is part of the header, which should be quite full... a more full header may be:

$headers = "MIME-Version: 1.0\r\nContent-type: text/html; charset=iso-8859-1\r\nFrom: Webmaster <admin@yourdomain.com>\r\nTo: Recipient <Recipients@email.add>\r\nReply-To: Webmaster <admin@yourdomain.com>\r\nX-Priority: 1\r\nX-MSMail-Priority: High\r\n X-Mailer: PHP mail function"
0
 
LVL 6

Expert Comment

by:DoppyNL
ID: 9745670
true, that can be in the header.

content-type --> php adds that automaticly (plain text)
from --> is set via another parameter in the mail-function
to --> is set via another parameter in the mail-function
reply-to --> can be usefull; indeed
priority --> don't set priority's to high all the time; it's so annoying when you get email that says priority "high" when in fact its just a joke.
x-mailer --> don't see any use for this header other then it will increase the size of the email with a couple of bytes.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question