Richard Korts
asked on
Using the mail function in php
It's incredible that it's so difficult to find out how to do something SO OBVIOUS.
I want to send a programatically generated email using the php mail function.
I want to specify BOTH a cc AND a from email address.
I finally figured out how to do one or the other, but not both.
Here's the code:
$mailto = "richard@rkassociates.com" ;
$subj = "On-Line Invoice Payment";
$body = "Some text";
$header = "From: payments@LSS.com \r\n Cc: richard@rkassociates.com";
$mres = mail($email, $subj, $body, $header);
The mail gets sent. Using the specific configuration above, there is NO from or cc.
If I specify EITHER JUST the From or the Cc in the $header variable, it works fine.
I've spent literally HOURS with Google, the php web site, etc., trying to figure this out.
Two questions:
(1) What's the trick?
(2) Why do they make it so INCREDIBLY difficult to do something SO SIMPLE?
I want to send a programatically generated email using the php mail function.
I want to specify BOTH a cc AND a from email address.
I finally figured out how to do one or the other, but not both.
Here's the code:
$mailto = "richard@rkassociates.com"
$subj = "On-Line Invoice Payment";
$body = "Some text";
$header = "From: payments@LSS.com \r\n Cc: richard@rkassociates.com";
$mres = mail($email, $subj, $body, $header);
The mail gets sent. Using the specific configuration above, there is NO from or cc.
If I specify EITHER JUST the From or the Cc in the $header variable, it works fine.
I've spent literally HOURS with Google, the php web site, etc., trying to figure this out.
Two questions:
(1) What's the trick?
(2) Why do they make it so INCREDIBLY difficult to do something SO SIMPLE?
Hi,
<?php
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
/* additional headers */
$headers .= "From: Your Name <yourname@example.com>\r\n ";
$headers .= "Cc: someone@anotherdomain.com\ r\n";
$headers .= "Bcc: someoneelse@somedomain.com \r\n";
$message = <<<MESSAGE
Whatever message you want to type may that be <b>bold</b> or may be any HTML text
MESSAGE;
mail("email@toaddress.com" ,"Message Title",$message,$headers);
?>
---
Harish
<?php
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
/* additional headers */
$headers .= "From: Your Name <yourname@example.com>\r\n
$headers .= "Cc: someone@anotherdomain.com\
$headers .= "Bcc: someoneelse@somedomain.com
$message = <<<MESSAGE
Whatever message you want to type may that be <b>bold</b> or may be any HTML text
MESSAGE;
mail("email@toaddress.com"
?>
---
Harish
$mailto = "richard@rkassociates.com" ;
$subj = "On-Line Invoice Payment";
$body = "Some text";
$header = "From: payments@LSS.com \r\n Cc";
$headers = "Cc: richard@rkassociates.com \r\n";
Gamebits
$subj = "On-Line Invoice Payment";
$body = "Some text";
$header = "From: payments@LSS.com \r\n Cc";
$headers = "Cc: richard@rkassociates.com \r\n";
Gamebits
ASKER
To mgh_mgharish
Your "headers" worked for the cc & the From. But now the To address is missing & the Body text formatting (using "\n\n" to skip a double line) doesn't work any more.
So it fixed some of it but broke other parts.
Your "headers" worked for the cc & the From. But now the To address is missing & the Body text formatting (using "\n\n" to skip a double line) doesn't work any more.
So it fixed some of it but broke other parts.
ASKER
To gamebits:
What SPECIFICALLY does the mail function look like. You have $header & $headers. I thought mail only accepted 4 arguments.
What SPECIFICALLY does the mail function look like. You have $header & $headers. I thought mail only accepted 4 arguments.
ASKER
To all:
I still think it's incredible that it's this difficult. If anybody can come up with the REAL solution, I'll give you 1000 points if Experts Exchange allows it.
I still think it's incredible that it's this difficult. If anybody can come up with the REAL solution, I'll give you 1000 points if Experts Exchange allows it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
To mgh_mgarish:
I just discoverd that I'm not passing the "to" address properly from the previous script. So that is MY error.
I'll fix that & I'll try <br>'s in the body text.
If those work, you get the points.
rkorts
I just discoverd that I'm not passing the "to" address properly from the previous script. So that is MY error.
I'll fix that & I'll try <br>'s in the body text.
If those work, you get the points.
rkorts
If you want to add other CCs/BCCs, then separate the the email ids by comma
ASKER
Substitute $mailto for $email in the mail function reference.