phpScheduleIt
May 21, 2013, 02:47:55 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: phpScheduleIt 2.4.2 has been released!
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: PHP Question to anyone who can answer  (Read 2082 times)
italianstalian
Newbie
*

Karma: 0
Posts: 31


« on: July 11, 2009, 08:55:08 AM »

In phpScheduleIt I have a form that generates invoices based on input by a user. I have a PHP script that I embedded in the output function that grabs a copy of that output and sends it in the background right before the output is displayed on the screen to print.

I want to be able CC an additional e-mail address but the trick is I want it to grab an e-mail address already entered in the invoice before it is submitted and send an additional copy to that address. Here is the code I'm using that works great so far.

<?php
$to = 'hiddenaddress@mywebsite.com';
$subject = 'Here's Your Receipt';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: hiddenaddress@mywebsite.com\r\nReply-To: DO NOT REPLY";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
//define the body of the message.
ob_start(); //Turn on output buffering
?>

--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

<html>
what's being sent
</html>

--PHP-alt-<?php echo $random_hash; ?>--
<?
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
//echo $mail_sent ? "Mail sent" : "Mail failed";
?>


The way the form posts it uses <?php print "$client_email"; ?> to output on the page and the copy that's sent. However, I want the e-mail that's entered to not only send to the hidden address but also to <?php print "$client_email"; ?>. Here's what I have and it's not working.

<?php
$to = '<?php print "$client_email"; ?>';
$bcc = 'hiddenaddress@mywebsite.com';

$subject = 'Here's Your Receipt';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: hiddenaddress@mywebsite.com\r\nReply-To: DO NOT REPLY";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
//define the body of the message.
ob_start(); //Turn on output buffering
?>


--PHP-alt-<?php echo $random_hash; ?>--
<?
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $to, $bcc, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
//echo $mail_sent ? "Mail sent" : "Mail failed";
?>


Basically I'm trying to get two copies of the HTML page to go out. One to the client and one to me so I can have a copy as well. ANY IDEAS?

Thanks,

ItalianStalian
« Last Edit: July 11, 2009, 09:00:16 AM by italianstalian » Logged
italianstalian
Newbie
*

Karma: 0
Posts: 31


« Reply #1 on: July 11, 2009, 11:37:46 AM »

I FIGURED IT OUT MYSELF...HERE'S THE SOLUTION!

<?php
$to = 'hiddenaddress@mywebsite.com';
$subject = 'Here's Your Receipt';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: hiddenaddress@mywebsite.com\r\nReply-To: DO NOT REPLY";
$headers = "CC: $client_email\r\nReply-To: DO NOT REPLY";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
//define the body of the message.
ob_start(); //Turn on output buffering
?>

--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

<html>
what's being sent
</html>

--PHP-alt-<?php echo $random_hash; ?>--
<?
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
//echo $mail_sent ? "Mail sent" : "Mail failed";
?>


This took care of it. Now I get an e-mail to the fixed address as well as a copy to the $client_email which is inputted when the person fills out the form.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2006-2007, Simple Machines Valid XHTML 1.0! Valid CSS!