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
Solved

Using the mail function in php

Posted on 2006-06-16
9
187 Views
Last Modified: 2006-11-18
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?

0
Comment
Question by:Richard Korts
  • 5
  • 3
9 Comments
 

Author Comment

by:Richard Korts
ID: 16924251
I sent the wrong version.

Substitute $mailto for $email in the mail function reference.
0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 16924276
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
0
 
LVL 28

Expert Comment

by:gamebits
ID: 16924280
$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
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:Richard Korts
ID: 16924465
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.
0
 

Author Comment

by:Richard Korts
ID: 16924472
To gamebits:

What SPECIFICALLY does the mail function look like. You have $header & $headers. I thought mail only accepted 4 arguments.

0
 

Author Comment

by:Richard Korts
ID: 16924482
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.
0
 
LVL 37

Accepted Solution

by:
Harisha M G earned 500 total points
ID: 16924486
Inside the body, you must use HTML Formatting.. use <br> instead of \n

I don't understand this: To address is missing ??

Where is the mail sent to ? Instead of putting "email@toaddress.com" inside the mail() function, you can use $mailto
0
 

Author Comment

by:Richard Korts
ID: 16924503
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
0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 16924600
If you want to add other CCs/BCCs, then separate the the email ids by comma
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

809 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