will35010 Posted August 11, 2009 Share Posted August 11, 2009 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!!! Quote Link to comment https://forums.phpfreaks.com/topic/169777-solved-concatenation-problem/ Share on other sites More sharing options...
JonnoTheDev Posted August 11, 2009 Share Posted August 11, 2009 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/169777-solved-concatenation-problem/#findComment-895658 Share on other sites More sharing options...
JonnoTheDev Posted August 11, 2009 Share Posted August 11, 2009 The printf() or sprintf() functions may also be easier for you if you have trouble concatinating variables. Look them up on php.net Quote Link to comment https://forums.phpfreaks.com/topic/169777-solved-concatenation-problem/#findComment-895660 Share on other sites More sharing options...
will35010 Posted August 11, 2009 Author Share Posted August 11, 2009 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 = 'edward.pipkin@trilakesmc.com' . ', '; $to = 'will.morris@trilakesmc.com'; $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: will.morris@trilakesmc.com\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. Quote Link to comment https://forums.phpfreaks.com/topic/169777-solved-concatenation-problem/#findComment-895664 Share on other sites More sharing options...
premiso Posted August 11, 2009 Share Posted August 11, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/169777-solved-concatenation-problem/#findComment-895667 Share on other sites More sharing options...
JonnoTheDev Posted August 11, 2009 Share Posted August 11, 2009 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; Quote Link to comment https://forums.phpfreaks.com/topic/169777-solved-concatenation-problem/#findComment-895672 Share on other sites More sharing options...
will35010 Posted August 11, 2009 Author Share Posted August 11, 2009 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 = 'edward.pipkin@trilakesmc.com' . ', '; $to = 'will.morris@trilakesmc.com'; $subject = 'Tri-Lakes Medical Center Patient Cheer Card'; $headers = "From: will.morris@trilakesmc.com\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'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/169777-solved-concatenation-problem/#findComment-895701 Share on other sites More sharing options...
JonnoTheDev Posted August 11, 2009 Share Posted August 11, 2009 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 = 'will.morris@trilakesmc.com'; $subject = 'Tri-Lakes Medical Center Patient Cheer Card'; $headers = "From: will.morris@trilakesmc.com\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'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/169777-solved-concatenation-problem/#findComment-895723 Share on other sites More sharing options...
will35010 Posted August 11, 2009 Author Share Posted August 11, 2009 Thanks!!! That did it! I really appreciate it! 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 = 'will.morris@trilakesmc.com'; $subject = 'Tri-Lakes Medical Center Patient Cheer Card'; $headers = "From: will.morris@trilakesmc.com\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'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/169777-solved-concatenation-problem/#findComment-895725 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.