Solved

Email from with PHP object?

Posted on 2003-11-13
4
259 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 250 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now