Jump to content

[SOLVED] concatenation problem


will35010

Recommended Posts

What am I doing wrong here? I know it has something to do with concatenation, but I can't figure it out.

 

My Code:

$message .= 	"Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
  	."Content-Transfer-Encoding: 7bit\r\n\r\n"
  	."Hey .$fname $lname .,. $yourname. has sent you a CheerCard.\r\n
  	."Message: .$message. \r\n
  	."Room #: $room
  	.$bound;

 

Original Working Code:

$message .= 	"Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
  	."Content-Transfer-Encoding: 7bit\r\n\r\n"
  	."hey my <b>good</b> friend here is a picture of our card\r\n"
  	.$bound;

 

Thanks!!!  :D

Link to comment
https://forums.phpfreaks.com/topic/169777-solved-concatenation-problem/
Share on other sites

Do you have a php editor that uses colour coding? Makes the job a hell of a lot easier.

<?php
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n
Content-Transfer-Encoding: 7bit\r\n\r\n
Hey ".$fname." ".$lname .", ".$yourname." has sent you a CheerCard.\r\nMessage: ".
$message."\r\nRoom #: ".$room.$bound;
?>

Do you have a php editor that uses colour coding? Makes the job a hell of a lot easier.

<?php
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n
Content-Transfer-Encoding: 7bit\r\n\r\n
Hey ".$fname." ".$lname .", ".$yourname." has sent you a CheerCard.\r\nMessage: ".
$message."\r\nRoom #: ".$room.$bound;
?>

 

I have phpDesigner, but it sucks. I need to get a better editor. That worked for the message part, but it messed up my attachment. Here is the entire script if that helps:

 

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1); 


/**
* @author Will Morris
* @copyright 2009
*/
//assign varible names to POST data

//card wanted
$card = $_POST['card'];

//form info
$sendername = $_POST['yourname'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$room = $_POST['room'];
$message = $_POST['message'];

//logic to get link of card chosen
if($card == 'baby') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/baby.jpg");
}
else if($card == 'baby2') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/baby2.jpg");
}
else if($card == 'baby3') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/baby3.jpg");
}
else if($card == 'baby-angel') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/baby-angel.jpg");
}
else if($card == 'baby-in-flower') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/baby-in-flower.jpg");
}
else if($card == 'daughter1') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/daughter1.jpg");
}
else if($card == 'new-kid1') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/new-kid1.jpg");
}
else if($card == 'twins-2') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/twins-2.jpg");
}
else if($card == 'getwell') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/getwell.jpg");
}
else if($card == 'getwellsoon-1') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/getwellsoon-1.jpg");
}
else if($card == 'recovery-2') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/recovery-2.jpg");
}
else if($card == 'footprints') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/footprints.jpg");
}
else if($card == 'thinking-of-you2') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/thinking-of-you2.jpg");
}
else {
echo "You didn't choose a card!";
}


//email part
//$to = '[email protected]' . ', ';
$to = '[email protected]';
$subject = 	'Tri-Lakes Medical Center Patient Cheer Card';
$bound_text = 	"Tri-Lakes Medical Center";
$bound = 	"--".$bound_text."\r\n";
$bound_last = 	"--".$bound_text."--\r\n";
  	 
$headers = 	"From: [email protected]\r\n";
$headers .= 	"MIME-Version: 1.0\r\n"
  	."Content-Type: multipart/mixed; boundary=\"$bound_text\"";

  	 
$message .= 	"If you can see this, then your client doesn't accept HTML email!\r\n"
  	.$bound;
  	 
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n
Content-Transfer-Encoding: 7bit\r\n\r\n
Hey ".$fname." ".$lname .", ".$yourname." has sent you a CheerCard.\r\nMessage: ".
$message."\r\nRoom #: ".$room.$bound;
  	 
$message .= 	"Content-Type: image/jpg; name=\"CheerCard.jpg\"\r\n"
  	."Content-Transfer-Encoding: base64\r\n"
  	."Content-disposition: attachment; file=\"CheerCard.jpg\"\r\n"
  	."\r\n"
  	.chunk_split(base64_encode($file))
  	.$bound_last;

if(mail($to, $subject, $message, $headers))
{
     echo 'MAIL SENT';
} else {
     echo 'MAIL FAILED';
}



?>

 

This is what was on the email:

Content-Transfer-Encoding: 7bit Hey will morris, has sent you a CheerCard. Message: If you can see this, then your client doesn't accept HTML email!

 

and it attached a text file that was unreadable instead of the picture.  :facewall:

I believe the content-type, content-disposition, content-transfer-encoding and the actual chunk (I think the chunk at least) should be apart of the headers. Not apart of the message.

 

Move those to apart of $headers instead of $message. $message is expected to be text, hence why you actually see it.

 

If all else fails check the mail function on the php site. Especially the user comments. I believe there will be examples of adding attachments.

The body of the message should come at the end. Not within the message header.

Also you have the variable $message used twice. See below:

$message .= "\r\nHey ".$fname." ".$lname .", ".$yourname." has sent you a CheerCard.\r\nMessage: ".
// this part is bad
$message.
"\r\nRoom #: ".$room.$bound;

I tried this, but it doesn't work either. What am I doing wrong?

 

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1); 


/**
* @author Will Morris
* @copyright 2009
*/
//assign varible names to POST data

//card wanted
$card = $_POST['card'];

//form info
$sendername = $_POST['yourname'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$room = $_POST['room'];
$sendermessage = $_POST['message'];

//logic to get link of card chosen
if($card == 'baby') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/baby.jpg");
}
else if($card == 'baby2') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/baby2.jpg");
}
else if($card == 'baby3') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/baby3.jpg");
}
else if($card == 'baby-angel') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/baby-angel.jpg");
}
else if($card == 'baby-in-flower') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/baby-in-flower.jpg");
}
else if($card == 'daughter1') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/daughter1.jpg");
}
else if($card == 'new-kid1') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/new-kid1.jpg");
}
else if($card == 'twins-2') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/twins-2.jpg");
}
else if($card == 'getwell') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/getwell.jpg");
}
else if($card == 'getwellsoon-1') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/getwellsoon-1.jpg");
}
else if($card == 'recovery-2') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/recovery-2.jpg");
}
else if($card == 'footprints') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/footprints.jpg");
}
else if($card == 'thinking-of-you2') {
$file = 	file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/thinking-of-you2.jpg");
}
else {
echo "You didn't choose a card!";
}


//email part
//$to = '[email protected]' . ', ';
$to = '[email protected]';
$subject = 	'Tri-Lakes Medical Center Patient Cheer Card';
  	 
$headers = 	"From: [email protected]\r\n
            MIME-Version: 1.0\r\n
            Content-Type: multipart/mixed; boundary=\"$bound_text\"
            Content-Type: image/jpg; name=\"CheerCard.jpg\"\r\n
  	       .Content-Transfer-Encoding: base64\r\n
           .Content-disposition: attachment; file=\"CheerCard.jpg\"\r\n
  	       ."\r\n"
  	       .chunk_split(base64_encode($file))";

$message = "Content-Type: text/html; charset=\"iso-8859-1\"\r\n
Content-Transfer-Encoding: 7bit\r\n\r\n
Hey ".$fname." ".$lname .", ".$sendername." has sent you a CheerCard.\r\nMessage: ".
$sendermessage."\r\nRoom #: ".$room.";
  	 
if(mail($to, $subject, $message, $headers))
{
     echo 'MAIL SENT';
} else {
     echo 'MAIL FAILED';
}



?>

I've not checked those mail headers but the code is cleaner

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1); 
/**
* @author Will Morris
* @copyright 2009
*/
//assign varible names to POST data

//card wanted
$card 			= $_POST['card'];
//form info
$sendername 	= $_POST['yourname'];
$fname 			= $_POST['fname'];
$lname 			= $_POST['lname'];
$room 			= $_POST['room'];
$sendermessage 	= $_POST['message'];

//logic to get link of card chosen
if(strlen($card)) {
$file = file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/".$card.".jpg");
}
else {
echo "You didn't choose a card!";
exit();
}
//email part
$to 		= '[email protected]';
$subject 	= 'Tri-Lakes Medical Center Patient Cheer Card';
  	 
$headers 	= "From: [email protected]\r\n
            	MIME-Version: 1.0\r\n
            	Content-Type: multipart/mixed; boundary=\"$bound_text\"
            Content-Type: image/jpg; name=\"CheerCard.jpg\"\r\n
  		       	Content-Transfer-Encoding: base64\r\n
           		Content-disposition: attachment; file=\"CheerCard.jpg\"\r\n".chunk_split(base64_encode($file));

$message 	= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n
			Content-Transfer-Encoding: 7bit\r\n\r\n
			Hey ".$fname." ".$lname .", ".$sendername." has sent you a CheerCard.\r\nMessage: ".$sendermessage."\r\nRoom #: ".$room;
  	 
if(mail($to, $subject, $message, $headers)) {
echo 'MAIL SENT';
} else {
echo 'MAIL FAILED';
}
?>

Thanks!!! That did it! I really appreciate it!  :D

 

I've not checked those mail headers but the code is cleaner

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1); 
/**
* @author Will Morris
* @copyright 2009
*/
//assign varible names to POST data

//card wanted
$card 			= $_POST['card'];
//form info
$sendername 	= $_POST['yourname'];
$fname 			= $_POST['fname'];
$lname 			= $_POST['lname'];
$room 			= $_POST['room'];
$sendermessage 	= $_POST['message'];

//logic to get link of card chosen
if(strlen($card)) {
$file = file_get_contents("http://www.trilakesmc.com/cheercards/cardtemplates/".$card.".jpg");
}
else {
echo "You didn't choose a card!";
exit();
}
//email part
$to 		= '[email protected]';
$subject 	= 'Tri-Lakes Medical Center Patient Cheer Card';
  	 
$headers 	= "From: [email protected]\r\n
            	MIME-Version: 1.0\r\n
            	Content-Type: multipart/mixed; boundary=\"$bound_text\"
            Content-Type: image/jpg; name=\"CheerCard.jpg\"\r\n
  		       	Content-Transfer-Encoding: base64\r\n
           		Content-disposition: attachment; file=\"CheerCard.jpg\"\r\n".chunk_split(base64_encode($file));

$message 	= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n
			Content-Transfer-Encoding: 7bit\r\n\r\n
			Hey ".$fname." ".$lname .", ".$sendername." has sent you a CheerCard.\r\nMessage: ".$sendermessage."\r\nRoom #: ".$room;
  	 
if(mail($to, $subject, $message, $headers)) {
echo 'MAIL SENT';
} else {
echo 'MAIL FAILED';
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.