Solved

Email from with PHP object?

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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 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…

734 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