Solved

Email from with PHP object?

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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

623 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