php send mail

Thsi code works fine for sending email if the "From" field is filled in
It does not work at all if the "From" and "CC" field s are filled in
Could someone please explain:

--------------------------------------------------

<?php

session_start();

if ($_POST['email']) {

            $headers  = 'MIME-Version: 1.0' . "\r\n";
            $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

if ($_POST['cc']) {
            $headers .= "Cc: $_POST[cc]" . "\r\n";
}            

            $email_to = $_POST['email'];
                $subject = "Support Links from TickTockIT";

            $headers .= 'From: Tick Tock IT <info@ticktockit.net>' . "\r\n";            

            ob_start();
                  include('email-content.php');
                  $message = ob_get_contents();
            ob_end_clean();

            mail($email_to, $subject, $message, $headers);

$_SESSION['sent'] = 1;
header('Location: send-email_b.php'); die;
}

?>

---------------------------------------
doctorbillTechAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
Try this.
$headers .= "Cc: ".$_POST['cc']. "\r\n";

Open in new window

0
doctorbillTechAuthor Commented:
Sorry - still not doing it
Same problem
0
Ray PaseurCommented:
Please give us a little more clue than "works" or "not."  When it fails, is there any error message?  Is there any line number?  If we can get a few more of these important clues we may be able to help.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

doctorbillTechAuthor Commented:
If the "From" email firld is filled in then the email is sent
If the "From" email field and the "CC" email field are both filled in then nothing is sent
No error message - the script runs and the "your message has been sent" is displayed on my screen
I have attached the full page below
send-email-b.php
0
Dave BaldwinFixer of ProblemsCommented:
After I killed the 'require_once' lines, I still get...

PHP Notice: Undefined index: email in C:\Inetpub\wwwroot\ee2\drbill\send-email-b.php on line 5

The first time the page is run, 'email' is undefined.

This version works to send email to both the 'To:' and the 'Cc:' after I killed the 'require_once' lines.  You can change it back to your email address.
<?php

session_start();

if (isset($_POST['email'])) {

		$headers  = 'MIME-Version: 1.0' . "\r\n";
		$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

if ($_POST['cc']) {
		$headers .= "Cc: ".$_POST['cc']. "\r\n";
	}		

		$email_to = $_POST['email'];
    $subject = "Support Links from TickTockIT";

		//$headers .= 'From: Tick Tock IT <info@ticktockit.net>' . "\r\n";		
		$headers .= 'From: Dave <dave@dibsplace.com>' . "\r\n";		

		ob_start();
			include('email-content.php');
			$message = ob_get_contents();
		ob_end_clean();

		mail($email_to, $subject, $message, $headers);

$_SESSION['sent'] = 1;
//header('Location: send-email_b.php'); die;
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Send Email</title>
</head>

<body>
<?php //require_once('../../../TickTock_int/menu_mailer.html'); ?>
<div align="center"><?php if (isset($_SESSION['sent'])) { ?>
Your message has been sent.
<?php } ?></div>

<br />
<br />
<div align="center">
<div style="width:350px;" align="left">
<center><?php //require_once('logo_header.php'); ?>Logo</center>

<form id="form1" name="form1" method="post" action="">
 
  <left>Contact email address:&nbsp;</em><input name="email" type="text" id="email" /></left>
  <br />
  <br />
  
  <left><em>CC:&nbsp;</em><input name="cc" type="text" id="cc" /></left>
  <br />
  <br />
  <input type="submit" name="Submit" value="Submit" style="float:right;"/>
</form></div>
</div>
</body>
</html>

<?php unset($_SESSION['sent']); ?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
doctorbillTechAuthor Commented:
I used your code bbut with my email address
Still the same problem

Could this be a php.ini config issue ?
0
Dave BaldwinFixer of ProblemsCommented:
I don't see how unless you don't have a SMTP server defined.  If you used my code, you should end up back on the same page because I commented out the 'header' redirect line.
0
doctorbillTechAuthor Commented:
It is working now
It looks as if one of the cc email address I was using was not being recognised correctly

Thanks all
0
doctorbillTechAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 125 points for Dave Baldwin's comment #a40694106
Assisted answer: 125 points for Dave Baldwin's comment #a40694076
Assisted answer: 125 points for Ray Paseur's comment #a40694098
Assisted answer: 0 points for doctorbill's comment #a40694121
Assisted answer: 125 points for Dave Baldwin's comment #a40694127

for the following reason:

Solution
0
doctorbillTechAuthor Commented:
Solution
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.