Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Email from with PHP object?

Posted on 2003-11-13
4
Medium Priority
?
310 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

718 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